From d906eb23f6cc86c69f7edc2732d7a46901b992a3 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Tue, 28 Apr 2020 14:17:21 +0800 Subject: [PATCH] Fixed bug #79526 (`__sleep` error message doesn't include the name of the class) --- ext/standard/tests/serialize/bug79526.phpt | 32 ++++++++++++++++++++++ ext/standard/var.c | 8 ++++-- 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 ext/standard/tests/serialize/bug79526.phpt 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-- + +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); -- 2.50.1