Add test for bug #79031

Fixed by preceding revert.
This commit is contained in:
Nikita Popov 2019-12-30 11:31:27 +01:00
parent ed3811e781
commit fcaf7cbd64
2 changed files with 74 additions and 0 deletions

3
NEWS
View file

@ -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)

View file

@ -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"
}
}
}