]> granicus.if.org Git - php/commitdiff
Fixed bug #79526 (`__sleep` error message doesn't include the name of the class)
authorXinchen Hui <laruence@gmail.com>
Tue, 28 Apr 2020 06:17:21 +0000 (14:17 +0800)
committerXinchen Hui <laruence@gmail.com>
Tue, 28 Apr 2020 06:17:21 +0000 (14:17 +0800)
ext/standard/tests/serialize/bug79526.phpt [new file with mode: 0644]
ext/standard/var.c

diff --git a/ext/standard/tests/serialize/bug79526.phpt b/ext/standard/tests/serialize/bug79526.phpt
new file mode 100644 (file)
index 0000000..b237df0
--- /dev/null
@@ -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
index 3652a631e31a07ecdb1e0f0b88cdd483b6f5cb99..609acf449e1fa0118571d3d6afc77cf052ce15ab 100644 (file)
@@ -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);