From 19bf1283813191ee362d5ed41eca05d63e3e7b4c Mon Sep 17 00:00:00 2001 From: Daniel Scherzer Date: Mon, 21 Oct 2024 16:01:59 -0700 Subject: [PATCH] GH-16317: allow `__debugInfo()` overrides for SplFixedArray subclasses For classes that extend `SplFixedArray` and define a `__debugInfo()` magic method, use it. --- ext/spl/spl_fixedarray.c | 10 ++++++++++ ext/spl/tests/gh16317.phpt | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 ext/spl/tests/gh16317.phpt diff --git a/ext/spl/spl_fixedarray.c b/ext/spl/spl_fixedarray.c index 5d7949308a303..657d6d9e44717 100644 --- a/ext/spl/spl_fixedarray.c +++ b/ext/spl/spl_fixedarray.c @@ -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). diff --git a/ext/spl/tests/gh16317.phpt b/ext/spl/tests/gh16317.phpt new file mode 100644 index 0000000000000..20970652ef476 --- /dev/null +++ b/ext/spl/tests/gh16317.phpt @@ -0,0 +1,19 @@ +--TEST-- +GH-16317 (__debugInfo() overrides don't work for SplFixedArray subclasses) +--FILE-- + 'y']; + } +} +var_dump( new Demo() ); + +?> +--EXPECT-- +object(Demo)#1 (1) { + ["x"]=> + string(1) "y" +}