1
0
mirror of https://github.com/php/php-src.git synced 2026-04-28 10:43:30 +02:00

Deref names returned by __sleep()

This commit is contained in:
Nikita Popov
2020-01-02 10:52:50 +01:00
parent 701e8c66d1
commit de0ca4734e
2 changed files with 19 additions and 0 deletions
@@ -0,0 +1,18 @@
--TEST--
__sleep() can return references
--FILE--
<?php
class Test {
public $x = 42;
public function __sleep() {
$name = 'x';
return [&$name];
}
}
var_dump(serialize(new Test));
?>
--EXPECT--
string(28) "O:4:"Test":1:{s:1:"x";i:42;}"
+1
View File
@@ -778,6 +778,7 @@ static void php_var_serialize_collect_names(HashTable *ht, HashTable *src) /* {{
zend_hash_init(ht, zend_hash_num_elements(src), NULL, NULL, 0);
ZEND_HASH_FOREACH_VAL(src, val) {
ZVAL_DEREF(val);
if (Z_TYPE_P(val) != IS_STRING) {
php_error_docref(NULL, E_NOTICE,
"__sleep should return an array only containing the names of instance-variables to serialize.");