File tree Expand file tree Collapse file tree 2 files changed +74
-0
lines changed Expand file tree Collapse file tree 2 files changed +74
-0
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,9 @@ PHP NEWS
47
47
. Fixed bug #78982 (pdo_pgsql returns dead persistent connection). (SATŌ
48
48
Kentarō)
49
49
50
+ - Session:
51
+ . Fixed bug #79031 (Session unserialization problem). (Nikita)
52
+
50
53
- Spl:
51
54
. Fixed bug #78976 (SplFileObject::fputcsv returns -1 on failure). (cmb)
52
55
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Bug #79031: Session unserialization problem
3
+ --FILE--
4
+ <?php
5
+
6
+ class SerializableClass implements Serializable {
7
+ public $ sharedProp ;
8
+ public function __construct ($ prop )
9
+ {
10
+ $ this ->sharedProp = $ prop ;
11
+ }
12
+ public function __set ($ key , $ value )
13
+ {
14
+ $ this ->$ key = $ value ;
15
+ }
16
+ public function serialize ()
17
+ {
18
+ return serialize (get_object_vars ($ this ));
19
+ }
20
+ public function unserialize ($ data )
21
+ {
22
+ $ ar = unserialize ($ data );
23
+ if ($ ar === false ) {
24
+ return ;
25
+ }
26
+ foreach ($ ar as $ k => $ v ) {
27
+ $ this ->__set ($ k , $ v );
28
+ }
29
+ }
30
+ }
31
+
32
+ // Shared object that acts as property of two another objects stored in session
33
+ $ testPropertyObj = new stdClass ();
34
+ $ testPropertyObj ->name = 'test ' ;
35
+
36
+ // Two instances of \SerializableClass that shares property
37
+ $ sessionObject = [
38
+ 'obj1 ' => new SerializableClass ($ testPropertyObj ),
39
+ 'obj2 ' => new SerializableClass ($ testPropertyObj ),
40
+ ];
41
+ session_start ();
42
+ $ _SESSION = $ sessionObject ;
43
+
44
+ $ sessionString = session_encode ();
45
+ session_decode ($ sessionString );
46
+ echo $ sessionString ;
47
+ echo "\n\n" ;
48
+ var_dump ($ _SESSION );
49
+
50
+ ?>
51
+ --EXPECT--
52
+ 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;}}
53
+
54
+ array(2) {
55
+ ["obj1"]=>
56
+ object(SerializableClass)#4 (1) {
57
+ ["sharedProp"]=>
58
+ object(stdClass)#5 (1) {
59
+ ["name"]=>
60
+ string(4) "test"
61
+ }
62
+ }
63
+ ["obj2"]=>
64
+ object(SerializableClass)#6 (1) {
65
+ ["sharedProp"]=>
66
+ object(stdClass)#5 (1) {
67
+ ["name"]=>
68
+ string(4) "test"
69
+ }
70
+ }
71
+ }
You can’t perform that action at this time.
0 commit comments