1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Merge branch 'PHP-8.4' into PHP-8.5

* PHP-8.4:
  Partially fix GH-16317: SimpleXML does not allow __debugInfo() overrides to work
This commit is contained in:
Niels Dossche
2025-10-12 11:25:31 +02:00
4 changed files with 34 additions and 6 deletions

View File

@@ -1179,12 +1179,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) /* {{{ */
{
@@ -2673,7 +2673,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;

View File

@@ -51,6 +51,8 @@ class SimpleXMLElement implements Stringable, Countable, RecursiveIterator
public function __toString(): string {}
public function __debugInfo(): ?array {}
/** @tentative-return-type */
public function count(): int {}

View File

@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 36eac2dee86bcc386c24e2cc14caa7bd3d709e82 */
* Stub hash: cee51320f0f09f14962fb72125ef8ff6073a642a */
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()
@@ -115,6 +118,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);
@@ -145,6 +149,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)

View File

@@ -0,0 +1,22 @@
--TEST--
GH-16317 (SimpleXML does not allow __debugInfo() overrides to work)
--FILE--
<?php
class MySXE extends SimpleXMLElement {
public function __debugInfo(): array {
echo "invoked\n";
return ['x' => 1];
}
}
$sxe = simplexml_load_string('<root><a/></root>', MySXE::class);
var_dump($sxe);
?>
--EXPECT--
invoked
object(MySXE)#1 (1) {
["x"]=>
int(1)
}