Skip to content

Commit efa1faf

Browse files
committed
Partially fix phpGH-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. Closes phpGH-20131.
1 parent 9216b8b commit efa1faf

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
@@ -22,6 +22,10 @@ PHP NEWS
2222
- Random:
2323
. Fix Randomizer::__serialize() w.r.t. INDIRECTs. (nielsdos)
2424

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

ext/simplexml/simplexml.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,12 +1225,12 @@ static HashTable *sxe_get_properties(zend_object *object) /* {{{ */
12251225
}
12261226
/* }}} */
12271227

1228-
static HashTable * sxe_get_debug_info(zend_object *object, int *is_temp) /* {{{ */
1228+
/* This custom handler exists because the var_dump adds a pseudo "@attributes" key. */
1229+
PHP_METHOD(SimpleXMLElement, __debugInfo)
12291230
{
1230-
*is_temp = 1;
1231-
return sxe_get_prop_hash(object, 1);
1231+
ZEND_PARSE_PARAMETERS_NONE();
1232+
RETURN_ARR(sxe_get_prop_hash(Z_OBJ_P(ZEND_THIS), 1));
12321233
}
1233-
/* }}} */
12341234

12351235
static int sxe_objects_compare(zval *object1, zval *object2) /* {{{ */
12361236
{
@@ -2733,7 +2733,6 @@ PHP_MINIT_FUNCTION(simplexml)
27332733
sxe_object_handlers.compare = sxe_objects_compare;
27342734
sxe_object_handlers.cast_object = sxe_object_cast;
27352735
sxe_object_handlers.count_elements = sxe_count_elements;
2736-
sxe_object_handlers.get_debug_info = sxe_get_debug_info;
27372736
sxe_object_handlers.get_closure = NULL;
27382737
sxe_object_handlers.get_gc = sxe_get_gc;
27392738

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)