1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Properly handle __debugInfo() returning an array reference

Currently, this fails because the type is IS_REFERENCE instead of
IS_ARRAY, but this could be confusing because a function return value is
normally dereferenced automatically in a lot of cases.

Closes GH-18762.
This commit is contained in:
Niels Dossche
2025-06-04 20:07:13 +02:00
parent 4c7220322b
commit 4f0554fa54
3 changed files with 26 additions and 0 deletions

1
NEWS
View File

@@ -14,6 +14,7 @@ PHP NEWS
. Drop support for -z CLI/CGI flag. (nielsdos)
. Fixed GH-17956 - development server 404 page does not adapt to mobiles.
(pascalchevrel)
. Properly handle __debugInfo() returning an array reference. (nielsdos)
- CURL:
. Added CURLFOLLOW_ALL, CURLFOLLOW_OBEYCODE and CURLFOLLOW_FIRSTONLY

View File

@@ -0,0 +1,22 @@
--TEST--
__debugInfo with reference return
--FILE--
<?php
class Test {
private $tmp = ['x' => 1];
public function &__debugInfo(): array
{
return $this->tmp;
}
}
var_dump(new Test);
?>
--EXPECT--
object(Test)#1 (1) {
["x"]=>
int(1)
}

View File

@@ -206,6 +206,9 @@ ZEND_API HashTable *zend_std_get_debug_info(zend_object *object, int *is_temp) /
}
zend_call_known_instance_method_with_0_params(ce->__debugInfo, object, &retval);
if (UNEXPECTED(Z_ISREF(retval))) {
zend_unwrap_reference(&retval);
}
if (Z_TYPE(retval) == IS_ARRAY) {
if (!Z_REFCOUNTED(retval)) {
*is_temp = 1;