Skip to content

Commit 4f0554f

Browse files
committed
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.
1 parent 4c72203 commit 4f0554f

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ PHP NEWS
1414
. Drop support for -z CLI/CGI flag. (nielsdos)
1515
. Fixed GH-17956 - development server 404 page does not adapt to mobiles.
1616
(pascalchevrel)
17+
. Properly handle __debugInfo() returning an array reference. (nielsdos)
1718

1819
- CURL:
1920
. Added CURLFOLLOW_ALL, CURLFOLLOW_OBEYCODE and CURLFOLLOW_FIRSTONLY

Zend/tests/__debugInfo_reference.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
__debugInfo with reference return
3+
--FILE--
4+
<?php
5+
6+
class Test {
7+
private $tmp = ['x' => 1];
8+
9+
public function &__debugInfo(): array
10+
{
11+
return $this->tmp;
12+
}
13+
}
14+
15+
var_dump(new Test);
16+
17+
?>
18+
--EXPECT--
19+
object(Test)#1 (1) {
20+
["x"]=>
21+
int(1)
22+
}

Zend/zend_object_handlers.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ ZEND_API HashTable *zend_std_get_debug_info(zend_object *object, int *is_temp) /
206206
}
207207

208208
zend_call_known_instance_method_with_0_params(ce->__debugInfo, object, &retval);
209+
if (UNEXPECTED(Z_ISREF(retval))) {
210+
zend_unwrap_reference(&retval);
211+
}
209212
if (Z_TYPE(retval) == IS_ARRAY) {
210213
if (!Z_REFCOUNTED(retval)) {
211214
*is_temp = 1;

0 commit comments

Comments
 (0)