From e3e1297d8caf14d39303b5b085c87ef3d7fcea6f Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sat, 11 Oct 2025 12:10:37 +0200 Subject: [PATCH] Fix GH-16317: DOM classes do not allow __debugInfo() overrides to work --- ext/dom/php_dom.c | 6 ++++++ ext/dom/tests/gh16317.phpt | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 ext/dom/tests/gh16317.phpt diff --git a/ext/dom/php_dom.c b/ext/dom/php_dom.c index 841dcd66186f8..d097081b0bdeb 100644 --- a/ext/dom/php_dom.c +++ b/ext/dom/php_dom.c @@ -401,6 +401,7 @@ static int dom_property_exists(zend_object *object, zend_string *name, int check } /* }}} */ +/* This custom handler is necessary to avoid a recursive construction of the entire subtree. */ static HashTable* dom_get_debug_info_helper(zend_object *object, int *is_temp) /* {{{ */ { dom_object *obj = php_dom_obj_from_obj(object); @@ -411,6 +412,11 @@ static HashTable* dom_get_debug_info_helper(zend_object *object, int *is_temp) / dom_prop_handler *entry; zend_string *object_str; + /* As we have a custom implementation, we must manually check for overrides. */ + if (object->ce->__debugInfo) { + return zend_std_get_debug_info(object, is_temp); + } + *is_temp = 1; std_props = zend_std_get_properties(object); diff --git a/ext/dom/tests/gh16317.phpt b/ext/dom/tests/gh16317.phpt new file mode 100644 index 0000000000000..870c337716f01 --- /dev/null +++ b/ext/dom/tests/gh16317.phpt @@ -0,0 +1,20 @@ +--TEST-- +GH-16317 (DOM classes do not allow __debugInfo() overrides to work) +--FILE-- + 'y']; + } +} + +var_dump(new Demo()); + +?> +--EXPECT-- +object(Demo)#1 (1) { + ["x"]=> + string(1) "y" +}