From c8390c5f19d6ece742da5b4428856b404223abd2 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sat, 11 Oct 2025 12:03:11 +0200 Subject: [PATCH 1/2] Fix GH-16317: SimpleXML does not allow __debugInfo() overrides to work If only we did not have the pseudo-key "@attributes", we could've just removed the custom get_debug_info implementation and this would work out of the box. Anyway, we just have to manually check for an override now. --- ext/simplexml/simplexml.c | 6 ++++++ ext/simplexml/tests/gh16317.phpt | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 ext/simplexml/tests/gh16317.phpt diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index 6eae5650340c5..62ea62b60a67c 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -1225,8 +1225,14 @@ static HashTable *sxe_get_properties(zend_object *object) /* {{{ */ } /* }}} */ +/* This custom handler exists because the var_dump adds a pseudo "@attributes" key. */ static HashTable * sxe_get_debug_info(zend_object *object, int *is_temp) /* {{{ */ { + /* 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; return sxe_get_prop_hash(object, 1); } diff --git a/ext/simplexml/tests/gh16317.phpt b/ext/simplexml/tests/gh16317.phpt new file mode 100644 index 0000000000000..db6c88022b19c --- /dev/null +++ b/ext/simplexml/tests/gh16317.phpt @@ -0,0 +1,22 @@ +--TEST-- +GH-16317 (SimpleXML does not allow __debugInfo() overrides to work) +--FILE-- + 1]; + } +} + +$sxe = simplexml_load_string('', MySXE::class); +var_dump($sxe); + +?> +--EXPECT-- +invoked +object(MySXE)#1 (1) { + ["x"]=> + int(1) +} From cb3f7c375c117080a025af7845ef935915e41978 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sat, 11 Oct 2025 23:48:47 +0200 Subject: [PATCH 2/2] Declare __debugInfo instead --- ext/simplexml/simplexml.c | 13 +++---------- ext/simplexml/simplexml.stub.php | 2 ++ ext/simplexml/simplexml_arginfo.h | 7 ++++++- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index 62ea62b60a67c..186db442ffa27 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -1226,17 +1226,11 @@ static HashTable *sxe_get_properties(zend_object *object) /* {{{ */ /* }}} */ /* This custom handler exists because the var_dump adds a pseudo "@attributes" key. */ -static HashTable * sxe_get_debug_info(zend_object *object, int *is_temp) /* {{{ */ +PHP_METHOD(SimpleXMLElement, __debugInfo) { - /* 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; - return sxe_get_prop_hash(object, 1); + ZEND_PARSE_PARAMETERS_NONE(); + RETURN_ARR(sxe_get_prop_hash(Z_OBJ_P(ZEND_THIS), 1)); } -/* }}} */ static int sxe_objects_compare(zval *object1, zval *object2) /* {{{ */ { @@ -2739,7 +2733,6 @@ PHP_MINIT_FUNCTION(simplexml) sxe_object_handlers.compare = sxe_objects_compare; sxe_object_handlers.cast_object = sxe_object_cast; sxe_object_handlers.count_elements = sxe_count_elements; - sxe_object_handlers.get_debug_info = sxe_get_debug_info; sxe_object_handlers.get_closure = NULL; sxe_object_handlers.get_gc = sxe_get_gc; diff --git a/ext/simplexml/simplexml.stub.php b/ext/simplexml/simplexml.stub.php index 4735573521587..b53730a97aeed 100644 --- a/ext/simplexml/simplexml.stub.php +++ b/ext/simplexml/simplexml.stub.php @@ -51,6 +51,8 @@ public function getName(): string {} public function __toString(): string {} + public function __debugInfo(): ?array {} + /** @tentative-return-type */ public function count(): int {} diff --git a/ext/simplexml/simplexml_arginfo.h b/ext/simplexml/simplexml_arginfo.h index f6100eb243e31..7401ffdb9a41c 100644 --- a/ext/simplexml/simplexml_arginfo.h +++ b/ext/simplexml/simplexml_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 06c88dc2fb5582a6d21c11aee6ac0a0538e70cbc */ + * Stub hash: 3da8d1222740f381602c0ec738fe6aa9dca56c8e */ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_simplexml_load_file, 0, 1, SimpleXMLElement, MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0) @@ -79,6 +79,9 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_SimpleXMLElement___toString, 0, 0, IS_STRING, 0) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_SimpleXMLElement___debugInfo, 0, 0, IS_ARRAY, 1) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_SimpleXMLElement_count, 0, 0, IS_LONG, 0) ZEND_END_ARG_INFO() @@ -116,6 +119,7 @@ ZEND_METHOD(SimpleXMLElement, addChild); ZEND_METHOD(SimpleXMLElement, addAttribute); ZEND_METHOD(SimpleXMLElement, getName); ZEND_METHOD(SimpleXMLElement, __toString); +ZEND_METHOD(SimpleXMLElement, __debugInfo); ZEND_METHOD(SimpleXMLElement, count); ZEND_METHOD(SimpleXMLElement, rewind); ZEND_METHOD(SimpleXMLElement, valid); @@ -148,6 +152,7 @@ static const zend_function_entry class_SimpleXMLElement_methods[] = { ZEND_ME(SimpleXMLElement, addAttribute, arginfo_class_SimpleXMLElement_addAttribute, ZEND_ACC_PUBLIC) ZEND_ME(SimpleXMLElement, getName, arginfo_class_SimpleXMLElement_getName, ZEND_ACC_PUBLIC) ZEND_ME(SimpleXMLElement, __toString, arginfo_class_SimpleXMLElement___toString, ZEND_ACC_PUBLIC) + ZEND_ME(SimpleXMLElement, __debugInfo, arginfo_class_SimpleXMLElement___debugInfo, ZEND_ACC_PUBLIC) ZEND_ME(SimpleXMLElement, count, arginfo_class_SimpleXMLElement_count, ZEND_ACC_PUBLIC) ZEND_ME(SimpleXMLElement, rewind, arginfo_class_SimpleXMLElement_rewind, ZEND_ACC_PUBLIC) ZEND_ME(SimpleXMLElement, valid, arginfo_class_SimpleXMLElement_valid, ZEND_ACC_PUBLIC)