From 8e0504c38b8fecbeef4b552705b5645f5f461b81 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 1/2] Partially fix GH-16317: DOM classes do not allow __debugInfo() overrides to work Closes GH-20132. --- NEWS | 4 ++++ ext/dom/php_dom.c | 6 ++++++ ext/dom/tests/gh16317.phpt | 20 ++++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 ext/dom/tests/gh16317.phpt diff --git a/NEWS b/NEWS index d8efbffb9c9..a1e87ca9c50 100644 --- a/NEWS +++ b/NEWS @@ -7,6 +7,10 @@ PHP NEWS . Fixed bug GH-20073 (Assertion failure in WeakMap offset operations on reference). (nielsdos) +- DOM: + . Partially fixed bug GH-16317 (DOM classes do not allow + __debugInfo() overrides to work). (nielsdos) + - FPM: . Fixed bug GH-19974 (fpm_status_export_to_zval segfault for parallel execution). (Jakub Zelenka, txuna) diff --git a/ext/dom/php_dom.c b/ext/dom/php_dom.c index 841dcd66186..d097081b0bd 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 00000000000..870c337716f --- /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" +} From 390e24397a27639ec993316cedf9720506f53c62 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Mon, 13 Oct 2025 18:45:26 +0200 Subject: [PATCH 2/2] Add forgotten NEWS item --- NEWS | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS b/NEWS index 1ffcaa8b061..e5b8670de5c 100644 --- a/NEWS +++ b/NEWS @@ -31,6 +31,7 @@ PHP NEWS . Fix memory leak of argument in webPhar. (nielsdos) . Fix memory leak when setAlias() fails. (nielsdos) . Fix memory leak in phar_parse_zipfile() error handling. (nielsdos) + . Fix file descriptor/memory leak when opening central fp fails. (nielsdos) - Random: . Fix Randomizer::__serialize() w.r.t. INDIRECTs. (nielsdos)