Skip to content

GH-16317: allow __debugInfo() overrides for SplFixedArray subclasses #16544

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions ext/spl/spl_fixedarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,16 @@ static HashTable* spl_fixedarray_object_get_properties_for(zend_object *obj, zen
/* This has __serialize, so the purpose is not ZEND_PROP_PURPOSE_SERIALIZE, which would expect a non-null return value */
ZEND_ASSERT(purpose != ZEND_PROP_PURPOSE_SERIALIZE);

/* GH-16317: allow subclasses to use __debugInfo() */
if (purpose == ZEND_PROP_PURPOSE_DEBUG && obj->ce->__debugInfo != NULL) {
int is_temp = 0;
HashTable *ht = zend_std_get_debug_info(obj, &is_temp);
if (ht && !is_temp) {
GC_TRY_ADDREF(ht);
}
return ht;
}

const spl_fixedarray_object *intern = spl_fixed_array_from_obj(obj);
/*
* SplFixedArray can be subclassed or have dynamic properties (With or without AllowDynamicProperties in subclasses).
Expand Down
19 changes: 19 additions & 0 deletions ext/spl/tests/gh16317.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
GH-16317 (__debugInfo() overrides don't work for SplFixedArray subclasses)
--FILE--
<?php

class Demo extends SplFixedArray {
public function __construct() {}
public function __debugInfo(): array {
return ['x' => 'y'];
}
}
var_dump( new Demo() );

?>
--EXPECT--
object(Demo)#1 (1) {
["x"]=>
string(1) "y"
}