Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions ext/dom/php_dom.c
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,18 @@ static int dom_property_exists(zend_object *object, zend_string *name, int check
}
/* }}} */

static void dom_unset_property(zend_object *object, zend_string *member, void **cache_slot)
{
dom_object *obj = php_dom_obj_from_obj(object);

if (obj->prop_handler != NULL && zend_hash_exists(obj->prop_handler, member)) {
zend_throw_error(NULL, "Cannot unset %s::$%s", ZSTR_VAL(object->ce->name), ZSTR_VAL(member));
return;
}

zend_std_unset_property(object, member, cache_slot);
}

static HashTable* dom_get_debug_info_helper(zend_object *object, int *is_temp) /* {{{ */
{
dom_object *obj = php_dom_obj_from_obj(object);
Expand Down Expand Up @@ -755,6 +767,7 @@ PHP_MINIT_FUNCTION(dom)
dom_object_handlers.read_property = dom_read_property;
dom_object_handlers.write_property = dom_write_property;
dom_object_handlers.get_property_ptr_ptr = dom_get_property_ptr_ptr;
dom_object_handlers.unset_property = dom_unset_property;
dom_object_handlers.clone_obj = dom_objects_store_clone_obj;
dom_object_handlers.has_property = dom_property_exists;
dom_object_handlers.get_debug_info = dom_get_debug_info;
Expand Down
32 changes: 32 additions & 0 deletions ext/dom/tests/unsetting_properties.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
--TEST--
Unsetting properties
--EXTENSIONS--
dom
--FILE--
<?php

class MyElement extends DOMElement {
public int $myProp = 3;
}

$dom = new DOMDocument;
$dom->registerNodeClass('DOMElement', 'MyElement');
$dom->loadXML('<root>foo</root>');
$root = $dom->documentElement;

unset($root->myProp);
try {
$root->myProp;
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
try {
unset($root->textContent);
} catch (Error $e) {
echo $e->getMessage(), "\n";
}

?>
--EXPECT--
Typed property MyElement::$myProp must not be accessed before initialization
Cannot unset MyElement::$textContent
Loading