Skip to content

Commit 19bf128

Browse files
GH-16317: allow __debugInfo() overrides for SplFixedArray subclasses
For classes that extend `SplFixedArray` and define a `__debugInfo()` magic method, use it.
1 parent 6dd67bb commit 19bf128

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

ext/spl/spl_fixedarray.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,16 @@ static HashTable* spl_fixedarray_object_get_properties_for(zend_object *obj, zen
225225
/* This has __serialize, so the purpose is not ZEND_PROP_PURPOSE_SERIALIZE, which would expect a non-null return value */
226226
ZEND_ASSERT(purpose != ZEND_PROP_PURPOSE_SERIALIZE);
227227

228+
/* GH-16317: allow subclasses to use __debugInfo() */
229+
if (purpose == ZEND_PROP_PURPOSE_DEBUG && obj->ce->__debugInfo != NULL) {
230+
int is_temp = 0;
231+
HashTable *ht = zend_std_get_debug_info(obj, &is_temp);
232+
if (ht && !is_temp) {
233+
GC_TRY_ADDREF(ht);
234+
}
235+
return ht;
236+
}
237+
228238
const spl_fixedarray_object *intern = spl_fixed_array_from_obj(obj);
229239
/*
230240
* SplFixedArray can be subclassed or have dynamic properties (With or without AllowDynamicProperties in subclasses).

ext/spl/tests/gh16317.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
GH-16317 (__debugInfo() overrides don't work for SplFixedArray subclasses)
3+
--FILE--
4+
<?php
5+
6+
class Demo extends SplFixedArray {
7+
public function __construct() {}
8+
public function __debugInfo(): array {
9+
return ['x' => 'y'];
10+
}
11+
}
12+
var_dump( new Demo() );
13+
14+
?>
15+
--EXPECT--
16+
object(Demo)#1 (1) {
17+
["x"]=>
18+
string(1) "y"
19+
}

0 commit comments

Comments
 (0)