diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index 6eae5650340c5..186db442ffa27 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -1225,12 +1225,12 @@ static HashTable *sxe_get_properties(zend_object *object) /* {{{ */ } /* }}} */ -static HashTable * sxe_get_debug_info(zend_object *object, int *is_temp) /* {{{ */ +/* This custom handler exists because the var_dump adds a pseudo "@attributes" key. */ +PHP_METHOD(SimpleXMLElement, __debugInfo) { - *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) /* {{{ */ { @@ -2733,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) 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) +}