Skip to content

Make a few unuseful DOMEntity properties readonly #7406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 26, 2021
Merged
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
3 changes: 0 additions & 3 deletions ext/dom/dom_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,8 @@ int dom_entity_public_id_read(dom_object *obj, zval *retval);
int dom_entity_system_id_read(dom_object *obj, zval *retval);
int dom_entity_notation_name_read(dom_object *obj, zval *retval);
int dom_entity_actual_encoding_read(dom_object *obj, zval *retval);
int dom_entity_actual_encoding_write(dom_object *obj, zval *newval);
int dom_entity_encoding_read(dom_object *obj, zval *retval);
int dom_entity_encoding_write(dom_object *obj, zval *newval);
int dom_entity_version_read(dom_object *obj, zval *retval);
int dom_entity_version_write(dom_object *obj, zval *newval);

/* namednodemap properties */
int dom_namednodemap_length_read(dom_object *obj, zval *retval);
Expand Down
15 changes: 0 additions & 15 deletions ext/dom/entity.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,6 @@ int dom_entity_actual_encoding_read(dom_object *obj, zval *retval)
return SUCCESS;
}

int dom_entity_actual_encoding_write(dom_object *obj, zval *newval)
{
return SUCCESS;
}

/* }}} */

/* {{{ encoding string
Expand All @@ -138,11 +133,6 @@ int dom_entity_encoding_read(dom_object *obj, zval *retval)
return SUCCESS;
}

int dom_entity_encoding_write(dom_object *obj, zval *newval)
{
return SUCCESS;
}

/* }}} */

/* {{{ version string
Expand All @@ -156,11 +146,6 @@ int dom_entity_version_read(dom_object *obj, zval *retval)
return SUCCESS;
}

int dom_entity_version_write(dom_object *obj, zval *newval)
{
return SUCCESS;
}

/* }}} */

#endif
6 changes: 3 additions & 3 deletions ext/dom/php_dom.c
Original file line number Diff line number Diff line change
Expand Up @@ -756,9 +756,9 @@ PHP_MINIT_FUNCTION(dom)
dom_register_prop_handler(&dom_entity_prop_handlers, "publicId", sizeof("publicId")-1, dom_entity_public_id_read, NULL);
dom_register_prop_handler(&dom_entity_prop_handlers, "systemId", sizeof("systemId")-1, dom_entity_system_id_read, NULL);
dom_register_prop_handler(&dom_entity_prop_handlers, "notationName", sizeof("notationName")-1, dom_entity_notation_name_read, NULL);
dom_register_prop_handler(&dom_entity_prop_handlers, "actualEncoding", sizeof("actualEncoding")-1, dom_entity_actual_encoding_read, dom_entity_actual_encoding_write);
dom_register_prop_handler(&dom_entity_prop_handlers, "encoding", sizeof("encoding")-1, dom_entity_encoding_read, dom_entity_encoding_write);
dom_register_prop_handler(&dom_entity_prop_handlers, "version", sizeof("version")-1, dom_entity_version_read, dom_entity_version_write);
dom_register_prop_handler(&dom_entity_prop_handlers, "actualEncoding", sizeof("actualEncoding")-1, dom_entity_actual_encoding_read, NULL);
dom_register_prop_handler(&dom_entity_prop_handlers, "encoding", sizeof("encoding")-1, dom_entity_encoding_read, NULL);
dom_register_prop_handler(&dom_entity_prop_handlers, "version", sizeof("version")-1, dom_entity_version_read, NULL);
zend_hash_merge(&dom_entity_prop_handlers, &dom_node_prop_handlers, dom_copy_prop_handler, 0);
zend_hash_add_ptr(&classes, dom_entity_class_entry->name, &dom_entity_prop_handlers);

Expand Down
21 changes: 15 additions & 6 deletions ext/dom/php_dom.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -619,14 +619,23 @@ class DOMEntity extends DOMNode
/** @readonly */
public ?string $notationName;

/** @readonly */
public mixed $actualEncoding = null;
/**
* @readonly
* @deprecated
*/
public ?string $actualEncoding = null;

/** @readonly */
public mixed $encoding = null;
/**
* @readonly
* @deprecated
*/
public ?string $encoding = null;

/** @readonly */
public mixed $version = null;
/**
* @readonly
* @deprecated
*/
public ?string $version = null;
}

class DOMEntityReference extends DOMNode
Expand Down
8 changes: 4 additions & 4 deletions ext/dom/php_dom_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: a01ea3d7803ba6099c79365ab8f45ca8d4f5d447 */
* Stub hash: ccaa66ce5837d475f6231d1a1eadefa8e74db6b9 */

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_dom_import_simplexml, 0, 1, DOMElement, 0)
ZEND_ARG_TYPE_INFO(0, node, IS_OBJECT, 0)
Expand Down Expand Up @@ -1578,19 +1578,19 @@ static zend_class_entry *register_class_DOMEntity(zend_class_entry *class_entry_
zval property_actualEncoding_default_value;
ZVAL_NULL(&property_actualEncoding_default_value);
zend_string *property_actualEncoding_name = zend_string_init("actualEncoding", sizeof("actualEncoding") - 1, 1);
zend_declare_typed_property(class_entry, property_actualEncoding_name, &property_actualEncoding_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_ANY));
zend_declare_typed_property(class_entry, property_actualEncoding_name, &property_actualEncoding_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING|MAY_BE_NULL));
zend_string_release(property_actualEncoding_name);

zval property_encoding_default_value;
ZVAL_NULL(&property_encoding_default_value);
zend_string *property_encoding_name = zend_string_init("encoding", sizeof("encoding") - 1, 1);
zend_declare_typed_property(class_entry, property_encoding_name, &property_encoding_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_ANY));
zend_declare_typed_property(class_entry, property_encoding_name, &property_encoding_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING|MAY_BE_NULL));
zend_string_release(property_encoding_name);

zval property_version_default_value;
ZVAL_NULL(&property_version_default_value);
zend_string *property_version_name = zend_string_init("version", sizeof("version") - 1, 1);
zend_declare_typed_property(class_entry, property_version_name, &property_version_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_ANY));
zend_declare_typed_property(class_entry, property_version_name, &property_version_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING|MAY_BE_NULL));
zend_string_release(property_version_name);

return class_entry;
Expand Down
23 changes: 23 additions & 0 deletions ext/dom/tests/property_write_errors.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,31 @@ try {
echo $exception->getMessage() . "\n";
}

$entity = new DOMEntity();

try {
$entity->actualEncoding = null;
} catch (Error $exception) {
echo $exception->getMessage() . "\n";
}

try {
$entity->encoding = null;
} catch (Error $exception) {
echo $exception->getMessage() . "\n";
}

try {
$entity->version = null;
} catch (Error $exception) {
echo $exception->getMessage() . "\n";
}

?>
--EXPECT--
Cannot assign array to property DOMNode::$nodeValue of type ?string
Cannot write read-only property DOMDocument::$nodeType
Cannot write read-only property DOMDocument::$xmlEncoding
Cannot write read-only property DOMEntity::$actualEncoding
Cannot write read-only property DOMEntity::$encoding
Cannot write read-only property DOMEntity::$version