summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXinchen Hui <laruence@gmail.com>2020-04-28 14:17:21 +0800
committerXinchen Hui <laruence@gmail.com>2020-04-28 14:17:21 +0800
commitd906eb23f6cc86c69f7edc2732d7a46901b992a3 (patch)
tree6b43359f2ab935b08082ef19610d16c86e71b299
parentacb1fa524043ebcf35228d1e006262bc4bb75ad5 (diff)
downloadphp-git-d906eb23f6cc86c69f7edc2732d7a46901b992a3.tar.gz
Fixed bug #79526 (`__sleep` error message doesn't include the name of the class)
-rw-r--r--ext/standard/tests/serialize/bug79526.phpt32
-rw-r--r--ext/standard/var.c8
2 files changed, 38 insertions, 2 deletions
diff --git a/ext/standard/tests/serialize/bug79526.phpt b/ext/standard/tests/serialize/bug79526.phpt
new file mode 100644
index 0000000000..b237df0d73
--- /dev/null
+++ b/ext/standard/tests/serialize/bug79526.phpt
@@ -0,0 +1,32 @@
+--TEST--
+Bug #79526 (`__sleep` error message doesn't include the name of the class)
+--FILE--
+<?php
+class A
+{
+ public function __sleep() {
+ return 1;
+ }
+}
+
+
+serialize(new A());
+
+class B
+{
+ public function __sleep() {
+ return [1];
+ }
+}
+
+
+serialize(new B());
+?>
+Done
+--EXPECTF--
+Notice: serialize(): A::__sleep should return an array only containing the names of instance-variables to serialize in %sbug79526.php on line %d
+
+Notice: serialize(): B::__sleep should return an array only containing the names of instance-variables to serialize in %sbug79526.php on line %d
+
+Notice: serialize(): "1" returned as member variable from __sleep() but does not exist in %sbug79526.php on line %d
+Done
diff --git a/ext/standard/var.c b/ext/standard/var.c
index 3652a631e3..609acf449e 100644
--- a/ext/standard/var.c
+++ b/ext/standard/var.c
@@ -729,8 +729,11 @@ static int php_var_serialize_call_sleep(zval *retval, zval *struc) /* {{{ */
}
if (!HASH_OF(retval)) {
+ zend_class_entry *ce;
+ ZEND_ASSERT(Z_TYPE_P(struc) == IS_OBJECT);
+ ce = Z_OBJCE_P(struc);
zval_ptr_dtor(retval);
- php_error_docref(NULL, E_NOTICE, "__sleep should return an array only containing the names of instance-variables to serialize");
+ 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));
return FAILURE;
}
@@ -811,7 +814,8 @@ static int php_var_serialize_get_sleep_props(
ZVAL_DEREF(name_val);
if (Z_TYPE_P(name_val) != IS_STRING) {
php_error_docref(NULL, E_NOTICE,
- "__sleep should return an array only containing the names of instance-variables to serialize.");
+ "%s::__sleep should return an array only containing the names of instance-variables to serialize",
+ ZSTR_VAL(ce->name));
}
name = zval_get_tmp_string(name_val, &tmp_name);