Skip to content

Commit d906eb2

Browse files
committed
Fixed bug #79526 (__sleep error message doesn't include the name of the class)
1 parent acb1fa5 commit d906eb2

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
Bug #79526 (`__sleep` error message doesn't include the name of the class)
3+
--FILE--
4+
<?php
5+
class A
6+
{
7+
public function __sleep() {
8+
return 1;
9+
}
10+
}
11+
12+
13+
serialize(new A());
14+
15+
class B
16+
{
17+
public function __sleep() {
18+
return [1];
19+
}
20+
}
21+
22+
23+
serialize(new B());
24+
?>
25+
Done
26+
--EXPECTF--
27+
Notice: serialize(): A::__sleep should return an array only containing the names of instance-variables to serialize in %sbug79526.php on line %d
28+
29+
Notice: serialize(): B::__sleep should return an array only containing the names of instance-variables to serialize in %sbug79526.php on line %d
30+
31+
Notice: serialize(): "1" returned as member variable from __sleep() but does not exist in %sbug79526.php on line %d
32+
Done

ext/standard/var.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -729,8 +729,11 @@ static int php_var_serialize_call_sleep(zval *retval, zval *struc) /* {{{ */
729729
}
730730

731731
if (!HASH_OF(retval)) {
732+
zend_class_entry *ce;
733+
ZEND_ASSERT(Z_TYPE_P(struc) == IS_OBJECT);
734+
ce = Z_OBJCE_P(struc);
732735
zval_ptr_dtor(retval);
733-
php_error_docref(NULL, E_NOTICE, "__sleep should return an array only containing the names of instance-variables to serialize");
736+
php_error_docref(NULL, E_NOTICE, "%s::__sleep should return an array only containing the names of instance-variables to serialize", ZSTR_VAL(ce->name));
734737
return FAILURE;
735738
}
736739

@@ -811,7 +814,8 @@ static int php_var_serialize_get_sleep_props(
811814
ZVAL_DEREF(name_val);
812815
if (Z_TYPE_P(name_val) != IS_STRING) {
813816
php_error_docref(NULL, E_NOTICE,
814-
"__sleep should return an array only containing the names of instance-variables to serialize.");
817+
"%s::__sleep should return an array only containing the names of instance-variables to serialize",
818+
ZSTR_VAL(ce->name));
815819
}
816820

817821
name = zval_get_tmp_string(name_val, &tmp_name);

0 commit comments

Comments
 (0)