Skip to content

Commit c8390c5

Browse files
committed
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.
1 parent ab9d121 commit c8390c5

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

ext/simplexml/simplexml.c

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

1228+
/* This custom handler exists because the var_dump adds a pseudo "@attributes" key. */
12281229
static HashTable * sxe_get_debug_info(zend_object *object, int *is_temp) /* {{{ */
12291230
{
1231+
/* As we have a custom implementation, we must manually check for overrides. */
1232+
if (object->ce->__debugInfo) {
1233+
return zend_std_get_debug_info(object, is_temp);
1234+
}
1235+
12301236
*is_temp = 1;
12311237
return sxe_get_prop_hash(object, 1);
12321238
}

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)