]> granicus.if.org Git - php/commitdiff
Skip non-existing properties returned by __sleep()
authorNicolas Grekas <nicolas.grekas@gmail.com>
Sat, 18 Apr 2020 10:22:00 +0000 (12:22 +0200)
committerChristoph M. Becker <cmbecker69@gmx.de>
Wed, 22 Apr 2020 14:41:04 +0000 (16:41 +0200)
UPGRADING
ext/standard/tests/serialize/bug14293.phpt
ext/standard/tests/serialize/bug69210.phpt
ext/standard/tests/serialize/sleep_undefined_declared_properties.phpt
ext/standard/var.c
tests/classes/bug26737.phpt

index 000e5866777d1dc57dca938d07ca979e1e63ed3a..568bdf584a448ea0e87748d8f0874ef3d77b166b 100644 (file)
--- a/UPGRADING
+++ b/UPGRADING
@@ -391,6 +391,9 @@ PHP 8.0 UPGRADE NOTES
     using serialize_precision rather than precision. In a default configuration,
     this means that floating-point numbers are now printed with full accuracy
     by these debugging functions.
+  . If the array returned by __sleep() contains non-existing properties, these
+    are now silently ignored. Previously, such properties would have been
+    serialized as if they had the value NULL.
 
 - tidy:
   . The $use_include_path parameter, which was not used internally, has been
index 875f8b2bc81e2951bbf7efa3b6d3b0edea6e98cf..ae108ba53a740e90967a01d3903ab386d803d8e2 100644 (file)
@@ -27,10 +27,8 @@ var_dump($t);
 __sleep called
 
 Notice: serialize(): "b" returned as member variable from __sleep() but does not exist in %sbug14293.php on line %d
-O:1:"t":2:{s:1:"a";s:5:"hello";s:1:"b";N;}
-object(t)#%d (2) {
+O:1:"t":1:{s:1:"a";s:5:"hello";}
+object(t)#%d (1) {
   ["a"]=>
   string(5) "hello"
-  ["b"]=>
-  NULL
 }
index 610c88f879bfa2c6a47b5f66ac6e5e6e92358696..41cc8f55f9a5d7eae261f1f931b951021cfa1ac0 100644 (file)
@@ -35,17 +35,13 @@ var_dump(unserialize($ss));
 var_dump(unserialize($si));
 ?>
 --EXPECT--
-O:10:"testString":2:{s:1:"a";b:1;s:1:"1";N;}
-O:11:"testInteger":2:{s:1:"a";b:1;s:1:"1";N;}
-object(testString)#3 (2) {
+O:10:"testString":1:{s:1:"a";b:1;}
+O:11:"testInteger":1:{s:1:"a";b:1;}
+object(testString)#3 (1) {
   ["a"]=>
   bool(true)
-  ["1"]=>
-  NULL
 }
-object(testInteger)#3 (2) {
+object(testInteger)#3 (1) {
   ["a"]=>
   bool(true)
-  ["1"]=>
-  NULL
 }
index ac33f4388cfbf26563b2df7e6a1f975dd0d09e3b..05a638cfba8d7f1bea64db56a3711d272bf82495 100644 (file)
@@ -26,4 +26,4 @@ Notice: serialize(): "pub" returned as member variable from __sleep() but does n
 Notice: serialize(): "prot" returned as member variable from __sleep() but does not exist in %s on line %d
 
 Notice: serialize(): "priv" returned as member variable from __sleep() but does not exist in %s on line %d
-string(53) "O:4:"Test":3:{s:3:"pub";N;s:4:"prot";N;s:4:"priv";N;}"
+string(15) "O:4:"Test":0:{}"
index e1bc4c5597f40cf1c052e89c18d28693b00541a3..9f15fc9e35b4a7bd8120a62018bacff0fa7fad0a 100644 (file)
@@ -861,7 +861,6 @@ static int php_var_serialize_get_sleep_props(
 
                php_error_docref(NULL, E_NOTICE,
                        "\"%s\" returned as member variable from __sleep() but does not exist", ZSTR_VAL(name));
-               zend_hash_add(ht, name, &EG(uninitialized_zval));
                zend_tmp_string_release(tmp_name);
        } ZEND_HASH_FOREACH_END();
 
index ac7b67f5c777fef0641edef877874cf3619c6630..f6f33fbf805f8579432c2e2308f4202871c5b7e5 100644 (file)
@@ -19,4 +19,4 @@ var_dump(str_replace("\0", '\0', $data));
 ?>
 --EXPECTF--
 Notice: serialize(): "no_such" returned as member variable from __sleep() but does not exist in %s on line %d
-string(130) "O:3:"foo":4:{s:12:"\0foo\0private";s:7:"private";s:12:"\0*\0protected";s:9:"protected";s:6:"public";s:6:"public";s:7:"no_such";N;}"
+string(114) "O:3:"foo":3:{s:12:"\0foo\0private";s:7:"private";s:12:"\0*\0protected";s:9:"protected";s:6:"public";s:6:"public";}"