Skip to content

Commit aa1585f

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Partially fix phpGH-16317: SimpleXML does not allow __debugInfo() overrides to work
2 parents 7d3c726 + efa1faf commit aa1585f

File tree

5 files changed

+38
-6
lines changed

5 files changed

+38
-6
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ PHP NEWS
2424
- Random:
2525
. Fix Randomizer::__serialize() w.r.t. INDIRECTs. (nielsdos)
2626

27+
- SimpleXML:
28+
. Partially fixed bug GH-16317 (SimpleXML does not allow __debugInfo() overrides
29+
to work). (nielsdos)
30+
2731
- XMLReader:
2832
. Fix arginfo/zpp violations when LIBXML_SCHEMAS_ENABLED is not available.
2933
(nielsdos)

ext/simplexml/simplexml.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,12 +1202,12 @@ static HashTable *sxe_get_properties(zend_object *object) /* {{{ */
12021202
}
12031203
/* }}} */
12041204

1205-
static HashTable * sxe_get_debug_info(zend_object *object, int *is_temp) /* {{{ */
1205+
/* This custom handler exists because the var_dump adds a pseudo "@attributes" key. */
1206+
PHP_METHOD(SimpleXMLElement, __debugInfo)
12061207
{
1207-
*is_temp = 1;
1208-
return sxe_get_prop_hash(object, 1);
1208+
ZEND_PARSE_PARAMETERS_NONE();
1209+
RETURN_ARR(sxe_get_prop_hash(Z_OBJ_P(ZEND_THIS), 1));
12091210
}
1210-
/* }}} */
12111211

12121212
static int sxe_objects_compare(zval *object1, zval *object2) /* {{{ */
12131213
{
@@ -2682,7 +2682,6 @@ PHP_MINIT_FUNCTION(simplexml)
26822682
sxe_object_handlers.compare = sxe_objects_compare;
26832683
sxe_object_handlers.cast_object = sxe_object_cast;
26842684
sxe_object_handlers.count_elements = sxe_count_elements;
2685-
sxe_object_handlers.get_debug_info = sxe_get_debug_info;
26862685
sxe_object_handlers.get_closure = NULL;
26872686
sxe_object_handlers.get_gc = sxe_get_gc;
26882687

ext/simplexml/simplexml.stub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public function getName(): string {}
5151

5252
public function __toString(): string {}
5353

54+
public function __debugInfo(): ?array {}
55+
5456
/** @tentative-return-type */
5557
public function count(): int {}
5658

ext/simplexml/simplexml_arginfo.h

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/simplexml/tests/gh16317.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
GH-16317 (SimpleXML does not allow __debugInfo() overrides to work)
3+
--FILE--
4+
<?php
5+
6+
class MySXE extends SimpleXMLElement {
7+
public function __debugInfo(): array {
8+
echo "invoked\n";
9+
return ['x' => 1];
10+
}
11+
}
12+
13+
$sxe = simplexml_load_string('<root><a/></root>', MySXE::class);
14+
var_dump($sxe);
15+
16+
?>
17+
--EXPECT--
18+
invoked
19+
object(MySXE)#1 (1) {
20+
["x"]=>
21+
int(1)
22+
}

0 commit comments

Comments
 (0)