summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2019-12-30 11:31:27 +0100
committerNikita Popov <nikita.ppv@gmail.com>2019-12-30 11:31:27 +0100
commitfcaf7cbd641dcbccdd5c6218a26abb34f7b6ff23 (patch)
tree2755a1f7b556a003dbf566edbd2368861471068c
parented3811e7819333cb097cb510cb8833527834c9a9 (diff)
downloadphp-git-fcaf7cbd641dcbccdd5c6218a26abb34f7b6ff23.tar.gz
Add test for bug #79031
Fixed by preceding revert.
-rw-r--r--NEWS3
-rw-r--r--ext/session/tests/bug79031.phpt71
2 files changed, 74 insertions, 0 deletions
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"
+ }
+ }
+}