Skip to content
Open
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
18 changes: 18 additions & 0 deletions ext/dom/php_dom.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,23 @@ static HashTable* dom_get_debug_info(zend_object *object, int *is_temp) /* {{{ *
}
/* }}} */

static HashTable *dom_get_properties_for(zend_object *obj, zend_prop_purpose purpose)
{
switch (purpose) {
case ZEND_PROP_PURPOSE_ARRAY_CAST:
zend_throw_error(NULL, "%s cannot be cast to an array because the properties are virtual and do not have a raw value", ZSTR_VAL(obj->ce->name));
return NULL;
case ZEND_PROP_PURPOSE_JSON:
zend_throw_error(NULL, "%s cannot be encoded to JSON because the properties are virtual and do not have a raw value", ZSTR_VAL(obj->ce->name));
return NULL;
case ZEND_PROP_PURPOSE_VAR_EXPORT:
zend_throw_error(NULL, "%s cannot be exported because the representation would be insufficient to restore the object from", ZSTR_VAL(obj->ce->name));
return NULL;
default:
return zend_std_get_properties_for(obj, purpose);
}
}

void *php_dom_export_node(zval *object) /* {{{ */
{
php_libxml_node_object *intern;
Expand Down Expand Up @@ -695,6 +712,7 @@ PHP_MINIT_FUNCTION(dom)
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;
dom_object_handlers.get_properties_for = dom_get_properties_for;

memcpy(&dom_modern_domimplementation_object_handlers, &dom_object_handlers, sizeof(zend_object_handlers));
/* The IDL has the [SameObject] constraint, which is incompatible with cloning because it imposes that there is only
Expand Down
11 changes: 0 additions & 11 deletions ext/dom/tests/DOMDocument_json_encode.phpt

This file was deleted.

28 changes: 28 additions & 0 deletions ext/dom/tests/get_properties_for.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--TEST--
Get properties for DOM nodes
--EXTENSIONS--
dom
--FILE--
<?php
$doc = new DOMDocument;
try {
json_encode($doc);
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
try {
(array) $doc;
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
try {
var_export($doc);
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
DOMDocument cannot be encoded to JSON because the properties are virtual and do not have a raw value
DOMDocument cannot be cast to an array because the properties are virtual and do not have a raw value
\DOMDocument::__set_state(array(
))DOMDocument cannot be exported because the representation would be insufficient to restore the object from