File tree Expand file tree Collapse file tree 2 files changed +25
-7
lines changed
Expand file tree Collapse file tree 2 files changed +25
-7
lines changed Original file line number Diff line number Diff line change @@ -4,12 +4,13 @@ Referencing an uninitialized typed property in __sleep() should be skipped
44<?php
55
66class Test {
7+ public ?int $ w = 123 ;
78 public int $ x ;
89 protected int $ y ;
910 private int $ z ;
1011
1112 public function __sleep () {
12- return ['x ' , 'y ' , 'z ' ];
13+ return ['w ' , ' x ' , 'y ' , 'z ' ];
1314 }
1415
1516 public function __set ($ name , $ val ) {
@@ -30,15 +31,23 @@ var_dump(unserialize(serialize($t)) == $t);
3031$ t ->z = 3 ;
3132var_dump (unserialize (serialize ($ t )) == $ t );
3233
34+ unset($ t ->w );
35+ $ s = serialize ($ t );
36+ $ t ->w = null ;
37+ var_dump (unserialize ($ s ) == $ t );
38+
3339var_dump ($ t );
3440?>
35- --EXPECT--
36- string(15) "O:4:"Test":0:{}"
41+ --EXPECTF--
42+ string(29) "O:4:"Test":1:{s:1:"w";i:123;}"
43+ bool(true)
3744bool(true)
3845bool(true)
3946bool(true)
4047bool(true)
41- object(Test)#1 (3) {
48+ object(Test)#1 (4) {
49+ ["w"]=>
50+ NULL
4251 ["x"]=>
4352 int(1)
4453 ["y":protected]=>
Original file line number Diff line number Diff line change @@ -782,11 +782,20 @@ static int php_var_serialize_try_add_sleep_prop(
782782 if (Z_TYPE_P (val ) == IS_INDIRECT ) {
783783 val = Z_INDIRECT_P (val );
784784 if (Z_TYPE_P (val ) == IS_UNDEF ) {
785- zend_property_info * info = zend_get_typed_property_info_for_slot (Z_OBJ_P (struc ), val );
786- if (info ) {
785+ zend_property_info * prop_info = zend_get_typed_property_info_for_slot (Z_OBJ_P (struc ), val );
786+ if (!prop_info ) {
787+ return FAILURE ;
788+ }
789+ zval * prop ;
790+ if ((prop_info -> flags & ZEND_ACC_STATIC ) != 0 ) {
791+ prop = & prop_info -> ce -> default_static_members_table [prop_info -> offset ];
792+ } else {
793+ prop = & prop_info -> ce -> default_properties_table [OBJ_PROP_TO_NUM (prop_info -> offset )];
794+ }
795+ if (Z_ISUNDEF_P (prop ) || !ZEND_TYPE_ALLOW_NULL (prop_info -> type )) {
787796 return SUCCESS ;
788797 }
789- return FAILURE ;
798+ val = & EG ( uninitialized_zval ) ;
790799 }
791800 }
792801
You can’t perform that action at this time.
0 commit comments