Skip to content

Commit 657f756

Browse files
nicolas-grekascmb69
authored andcommitted
Skip non-existing properties returned by __sleep()
1 parent d9a9662 commit 657f756

File tree

6 files changed

+11
-15
lines changed

6 files changed

+11
-15
lines changed

UPGRADING

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,9 @@ PHP 8.0 UPGRADE NOTES
391391
using serialize_precision rather than precision. In a default configuration,
392392
this means that floating-point numbers are now printed with full accuracy
393393
by these debugging functions.
394+
. If the array returned by __sleep() contains non-existing properties, these
395+
are now silently ignored. Previously, such properties would have been
396+
serialized as if they had the value NULL.
394397

395398
- tidy:
396399
. The $use_include_path parameter, which was not used internally, has been

ext/standard/tests/serialize/bug14293.phpt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@ var_dump($t);
2727
__sleep called
2828

2929
Notice: serialize(): "b" returned as member variable from __sleep() but does not exist in %sbug14293.php on line %d
30-
O:1:"t":2:{s:1:"a";s:5:"hello";s:1:"b";N;}
31-
object(t)#%d (2) {
30+
O:1:"t":1:{s:1:"a";s:5:"hello";}
31+
object(t)#%d (1) {
3232
["a"]=>
3333
string(5) "hello"
34-
["b"]=>
35-
NULL
3634
}

ext/standard/tests/serialize/bug69210.phpt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,13 @@ var_dump(unserialize($ss));
3535
var_dump(unserialize($si));
3636
?>
3737
--EXPECT--
38-
O:10:"testString":2:{s:1:"a";b:1;s:1:"1";N;}
39-
O:11:"testInteger":2:{s:1:"a";b:1;s:1:"1";N;}
40-
object(testString)#3 (2) {
38+
O:10:"testString":1:{s:1:"a";b:1;}
39+
O:11:"testInteger":1:{s:1:"a";b:1;}
40+
object(testString)#3 (1) {
4141
["a"]=>
4242
bool(true)
43-
["1"]=>
44-
NULL
4543
}
46-
object(testInteger)#3 (2) {
44+
object(testInteger)#3 (1) {
4745
["a"]=>
4846
bool(true)
49-
["1"]=>
50-
NULL
5147
}

ext/standard/tests/serialize/sleep_undefined_declared_properties.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ Notice: serialize(): "pub" returned as member variable from __sleep() but does n
2626
Notice: serialize(): "prot" returned as member variable from __sleep() but does not exist in %s on line %d
2727

2828
Notice: serialize(): "priv" returned as member variable from __sleep() but does not exist in %s on line %d
29-
string(53) "O:4:"Test":3:{s:3:"pub";N;s:4:"prot";N;s:4:"priv";N;}"
29+
string(15) "O:4:"Test":0:{}"

ext/standard/var.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,6 @@ static int php_var_serialize_get_sleep_props(
861861

862862
php_error_docref(NULL, E_NOTICE,
863863
"\"%s\" returned as member variable from __sleep() but does not exist", ZSTR_VAL(name));
864-
zend_hash_add(ht, name, &EG(uninitialized_zval));
865864
zend_tmp_string_release(tmp_name);
866865
} ZEND_HASH_FOREACH_END();
867866

tests/classes/bug26737.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ var_dump(str_replace("\0", '\0', $data));
1919
?>
2020
--EXPECTF--
2121
Notice: serialize(): "no_such" returned as member variable from __sleep() but does not exist in %s on line %d
22-
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;}"
22+
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";}"

0 commit comments

Comments
 (0)