From: Nikita Popov <nikita.ppv@gmail.com> Date: Mon, 30 Dec 2019 10:31:27 +0000 (+0100) Subject: Add test for bug #79031 X-Git-Tag: php-7.4.7RC1~365 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fcaf7cbd641dcbccdd5c6218a26abb34f7b6ff23;p=php Add test for bug #79031 Fixed by preceding revert. --- diff --git a/NEWS b/NEWS index 34bdac902c..464ac3d885 100644 --- a/NEWS +++ b/NEWS @@ -47,6 +47,9 @@ PHP NEWS . Fixed bug #78982 (pdo_pgsql returns dead persistent connection). (SATÅ KentarÅ) +- Session: + . Fixed bug #79031 (Session unserialization problem). (Nikita) + - Spl: . Fixed bug #78976 (SplFileObject::fputcsv returns -1 on failure). (cmb) diff --git a/ext/session/tests/bug79031.phpt b/ext/session/tests/bug79031.phpt new file mode 100644 index 0000000000..955e8ee695 --- /dev/null +++ b/ext/session/tests/bug79031.phpt @@ -0,0 +1,71 @@ +--TEST-- +Bug #79031: Session unserialization problem +--FILE-- +<?php + +class SerializableClass implements Serializable { + public $sharedProp; + public function __construct($prop) + { + $this->sharedProp = $prop; + } + public function __set($key, $value) + { + $this->$key = $value; + } + public function serialize() + { + return serialize(get_object_vars($this)); + } + public function unserialize($data) + { + $ar = unserialize($data); + if ($ar === false) { + return; + } + foreach ($ar as $k => $v) { + $this->__set($k, $v); + } + } +} + +// Shared object that acts as property of two another objects stored in session +$testPropertyObj = new stdClass(); +$testPropertyObj->name = 'test'; + +// Two instances of \SerializableClass that shares property +$sessionObject = [ + 'obj1' => new SerializableClass($testPropertyObj), + 'obj2' => new SerializableClass($testPropertyObj), +]; +session_start(); +$_SESSION = $sessionObject; + +$sessionString = session_encode(); +session_decode($sessionString); +echo $sessionString; +echo "\n\n"; +var_dump($_SESSION); + +?> +--EXPECT-- +obj1|C:17:"SerializableClass":65:{a:1:{s:10:"sharedProp";O:8:"stdClass":1:{s:4:"name";s:4:"test";}}}obj2|C:17:"SerializableClass":28:{a:1:{s:10:"sharedProp";r:3;}} + +array(2) { + ["obj1"]=> + object(SerializableClass)#4 (1) { + ["sharedProp"]=> + object(stdClass)#5 (1) { + ["name"]=> + string(4) "test" + } + } + ["obj2"]=> + object(SerializableClass)#6 (1) { + ["sharedProp"]=> + object(stdClass)#5 (1) { + ["name"]=> + string(4) "test" + } + } +}