Skip to content

Commit de0ca47

Browse files
committed
Deref names returned by __sleep()
1 parent 701e8c6 commit de0ca47

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
__sleep() can return references
3+
--FILE--
4+
<?php
5+
6+
class Test {
7+
public $x = 42;
8+
public function __sleep() {
9+
$name = 'x';
10+
return [&$name];
11+
}
12+
}
13+
14+
var_dump(serialize(new Test));
15+
16+
?>
17+
--EXPECT--
18+
string(28) "O:4:"Test":1:{s:1:"x";i:42;}"

ext/standard/var.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,7 @@ static void php_var_serialize_collect_names(HashTable *ht, HashTable *src) /* {{
778778

779779
zend_hash_init(ht, zend_hash_num_elements(src), NULL, NULL, 0);
780780
ZEND_HASH_FOREACH_VAL(src, val) {
781+
ZVAL_DEREF(val);
781782
if (Z_TYPE_P(val) != IS_STRING) {
782783
php_error_docref(NULL, E_NOTICE,
783784
"__sleep should return an array only containing the names of instance-variables to serialize.");

0 commit comments

Comments
 (0)