Skip to content

Commit ecc6b8c

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fix #79065: DOM classes do not expose properties to Reflection
2 parents f578d57 + 6bc8f7e commit ecc6b8c

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

ext/dom/php_dom.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,28 @@ static int dom_property_exists(zend_object *object, zend_string *name, int check
385385
}
386386
/* }}} */
387387

388+
/* {{{ dom_get_properties */
389+
static HashTable *dom_get_properties(zend_object *object)
390+
{
391+
dom_object *obj = php_dom_obj_from_obj(object);
392+
HashTable *props = zend_std_get_properties(object);
393+
394+
if (obj->prop_handler != NULL) {
395+
zend_string *key;
396+
dom_prop_handler *hnd;
397+
398+
ZEND_HASH_FOREACH_STR_KEY_PTR(obj->prop_handler, key, hnd) {
399+
zval val;
400+
401+
if (hnd->read_func(obj, &val) == SUCCESS) {
402+
zend_hash_update(props, key, &val);
403+
}
404+
} ZEND_HASH_FOREACH_END();
405+
}
406+
return props;
407+
}
408+
/* }}} */
409+
388410
static HashTable* dom_get_debug_info_helper(zend_object *object, int *is_temp) /* {{{ */
389411
{
390412
dom_object *obj = php_dom_obj_from_obj(object);
@@ -568,6 +590,7 @@ PHP_MINIT_FUNCTION(dom)
568590
dom_object_handlers.get_property_ptr_ptr = dom_get_property_ptr_ptr;
569591
dom_object_handlers.clone_obj = dom_objects_store_clone_obj;
570592
dom_object_handlers.has_property = dom_property_exists;
593+
dom_object_handlers.get_properties = dom_get_properties;
571594
dom_object_handlers.get_debug_info = dom_get_debug_info;
572595

573596
memcpy(&dom_nnodemap_object_handlers, &dom_object_handlers, sizeof(zend_object_handlers));

ext/dom/tests/bug79065.phpt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Bug #79065 (DOM classes do not expose properties to Reflection)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('dom')) die('skip dom extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
$dom = new DOMDocument;
10+
$dom->loadHTML('<b>test</b>');
11+
var_dump(count(get_object_vars($dom)));
12+
13+
$ro = new ReflectionObject($dom);
14+
var_dump(count($ro->getProperties()));
15+
var_dump($ro->hasProperty("textContent"));
16+
$rp = $ro->getProperty("textContent");
17+
var_dump($rp);
18+
var_dump($rp->getValue($dom));
19+
?>
20+
--EXPECTF--
21+
int(38)
22+
int(38)
23+
bool(true)
24+
object(ReflectionProperty)#%d (2) {
25+
["name"]=>
26+
string(11) "textContent"
27+
["class"]=>
28+
string(11) "DOMDocument"
29+
}
30+
string(4) "test"

0 commit comments

Comments
 (0)