Skip to content

Commit 8e0504c

Browse files
committed
Partially fix phpGH-16317: DOM classes do not allow __debugInfo() overrides to work
Closes phpGH-20132.
1 parent 3abebf3 commit 8e0504c

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ PHP NEWS
77
. Fixed bug GH-20073 (Assertion failure in WeakMap offset operations on
88
reference). (nielsdos)
99

10+
- DOM:
11+
. Partially fixed bug GH-16317 (DOM classes do not allow
12+
__debugInfo() overrides to work). (nielsdos)
13+
1014
- FPM:
1115
. Fixed bug GH-19974 (fpm_status_export_to_zval segfault for parallel
1216
execution). (Jakub Zelenka, txuna)

ext/dom/php_dom.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ static int dom_property_exists(zend_object *object, zend_string *name, int check
401401
}
402402
/* }}} */
403403

404+
/* This custom handler is necessary to avoid a recursive construction of the entire subtree. */
404405
static HashTable* dom_get_debug_info_helper(zend_object *object, int *is_temp) /* {{{ */
405406
{
406407
dom_object *obj = php_dom_obj_from_obj(object);
@@ -411,6 +412,11 @@ static HashTable* dom_get_debug_info_helper(zend_object *object, int *is_temp) /
411412
dom_prop_handler *entry;
412413
zend_string *object_str;
413414

415+
/* As we have a custom implementation, we must manually check for overrides. */
416+
if (object->ce->__debugInfo) {
417+
return zend_std_get_debug_info(object, is_temp);
418+
}
419+
414420
*is_temp = 1;
415421

416422
std_props = zend_std_get_properties(object);

ext/dom/tests/gh16317.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
GH-16317 (DOM classes do not allow __debugInfo() overrides to work)
3+
--FILE--
4+
<?php
5+
6+
class Demo extends DOMNode {
7+
public function __construct() {}
8+
public function __debugInfo(): array {
9+
return ['x' => 'y'];
10+
}
11+
}
12+
13+
var_dump(new Demo());
14+
15+
?>
16+
--EXPECT--
17+
object(Demo)#1 (1) {
18+
["x"]=>
19+
string(1) "y"
20+
}

0 commit comments

Comments
 (0)