Skip to content

Commit 25cbd08

Browse files
authored
Make a few unuseful DOMEntity properties readonly (#7406)
1 parent 2d248c8 commit 25cbd08

File tree

6 files changed

+45
-31
lines changed

6 files changed

+45
-31
lines changed

ext/dom/dom_properties.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,8 @@ int dom_entity_public_id_read(dom_object *obj, zval *retval);
7878
int dom_entity_system_id_read(dom_object *obj, zval *retval);
7979
int dom_entity_notation_name_read(dom_object *obj, zval *retval);
8080
int dom_entity_actual_encoding_read(dom_object *obj, zval *retval);
81-
int dom_entity_actual_encoding_write(dom_object *obj, zval *newval);
8281
int dom_entity_encoding_read(dom_object *obj, zval *retval);
83-
int dom_entity_encoding_write(dom_object *obj, zval *newval);
8482
int dom_entity_version_read(dom_object *obj, zval *retval);
85-
int dom_entity_version_write(dom_object *obj, zval *newval);
8683

8784
/* namednodemap properties */
8885
int dom_namednodemap_length_read(dom_object *obj, zval *retval);

ext/dom/entity.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,6 @@ int dom_entity_actual_encoding_read(dom_object *obj, zval *retval)
120120
return SUCCESS;
121121
}
122122

123-
int dom_entity_actual_encoding_write(dom_object *obj, zval *newval)
124-
{
125-
return SUCCESS;
126-
}
127-
128123
/* }}} */
129124

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

141-
int dom_entity_encoding_write(dom_object *obj, zval *newval)
142-
{
143-
return SUCCESS;
144-
}
145-
146136
/* }}} */
147137

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

159-
int dom_entity_version_write(dom_object *obj, zval *newval)
160-
{
161-
return SUCCESS;
162-
}
163-
164149
/* }}} */
165150

166151
#endif

ext/dom/php_dom.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -756,9 +756,9 @@ PHP_MINIT_FUNCTION(dom)
756756
dom_register_prop_handler(&dom_entity_prop_handlers, "publicId", sizeof("publicId")-1, dom_entity_public_id_read, NULL);
757757
dom_register_prop_handler(&dom_entity_prop_handlers, "systemId", sizeof("systemId")-1, dom_entity_system_id_read, NULL);
758758
dom_register_prop_handler(&dom_entity_prop_handlers, "notationName", sizeof("notationName")-1, dom_entity_notation_name_read, NULL);
759-
dom_register_prop_handler(&dom_entity_prop_handlers, "actualEncoding", sizeof("actualEncoding")-1, dom_entity_actual_encoding_read, dom_entity_actual_encoding_write);
760-
dom_register_prop_handler(&dom_entity_prop_handlers, "encoding", sizeof("encoding")-1, dom_entity_encoding_read, dom_entity_encoding_write);
761-
dom_register_prop_handler(&dom_entity_prop_handlers, "version", sizeof("version")-1, dom_entity_version_read, dom_entity_version_write);
759+
dom_register_prop_handler(&dom_entity_prop_handlers, "actualEncoding", sizeof("actualEncoding")-1, dom_entity_actual_encoding_read, NULL);
760+
dom_register_prop_handler(&dom_entity_prop_handlers, "encoding", sizeof("encoding")-1, dom_entity_encoding_read, NULL);
761+
dom_register_prop_handler(&dom_entity_prop_handlers, "version", sizeof("version")-1, dom_entity_version_read, NULL);
762762
zend_hash_merge(&dom_entity_prop_handlers, &dom_node_prop_handlers, dom_copy_prop_handler, 0);
763763
zend_hash_add_ptr(&classes, dom_entity_class_entry->name, &dom_entity_prop_handlers);
764764

ext/dom/php_dom.stub.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -619,14 +619,23 @@ class DOMEntity extends DOMNode
619619
/** @readonly */
620620
public ?string $notationName;
621621

622-
/** @readonly */
623-
public mixed $actualEncoding = null;
622+
/**
623+
* @readonly
624+
* @deprecated
625+
*/
626+
public ?string $actualEncoding = null;
624627

625-
/** @readonly */
626-
public mixed $encoding = null;
628+
/**
629+
* @readonly
630+
* @deprecated
631+
*/
632+
public ?string $encoding = null;
627633

628-
/** @readonly */
629-
public mixed $version = null;
634+
/**
635+
* @readonly
636+
* @deprecated
637+
*/
638+
public ?string $version = null;
630639
}
631640

632641
class DOMEntityReference extends DOMNode

ext/dom/php_dom_arginfo.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: a01ea3d7803ba6099c79365ab8f45ca8d4f5d447 */
2+
* Stub hash: ccaa66ce5837d475f6231d1a1eadefa8e74db6b9 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_dom_import_simplexml, 0, 1, DOMElement, 0)
55
ZEND_ARG_TYPE_INFO(0, node, IS_OBJECT, 0)
@@ -1578,19 +1578,19 @@ static zend_class_entry *register_class_DOMEntity(zend_class_entry *class_entry_
15781578
zval property_actualEncoding_default_value;
15791579
ZVAL_NULL(&property_actualEncoding_default_value);
15801580
zend_string *property_actualEncoding_name = zend_string_init("actualEncoding", sizeof("actualEncoding") - 1, 1);
1581-
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));
1581+
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));
15821582
zend_string_release(property_actualEncoding_name);
15831583

15841584
zval property_encoding_default_value;
15851585
ZVAL_NULL(&property_encoding_default_value);
15861586
zend_string *property_encoding_name = zend_string_init("encoding", sizeof("encoding") - 1, 1);
1587-
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));
1587+
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));
15881588
zend_string_release(property_encoding_name);
15891589

15901590
zval property_version_default_value;
15911591
ZVAL_NULL(&property_version_default_value);
15921592
zend_string *property_version_name = zend_string_init("version", sizeof("version") - 1, 1);
1593-
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));
1593+
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));
15941594
zend_string_release(property_version_name);
15951595

15961596
return class_entry;

ext/dom/tests/property_write_errors.phpt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,31 @@ try {
2626
echo $exception->getMessage() . "\n";
2727
}
2828

29+
$entity = new DOMEntity();
30+
31+
try {
32+
$entity->actualEncoding = null;
33+
} catch (Error $exception) {
34+
echo $exception->getMessage() . "\n";
35+
}
36+
37+
try {
38+
$entity->encoding = null;
39+
} catch (Error $exception) {
40+
echo $exception->getMessage() . "\n";
41+
}
42+
43+
try {
44+
$entity->version = null;
45+
} catch (Error $exception) {
46+
echo $exception->getMessage() . "\n";
47+
}
48+
2949
?>
3050
--EXPECT--
3151
Cannot assign array to property DOMNode::$nodeValue of type ?string
3252
Cannot write read-only property DOMDocument::$nodeType
3353
Cannot write read-only property DOMDocument::$xmlEncoding
54+
Cannot write read-only property DOMEntity::$actualEncoding
55+
Cannot write read-only property DOMEntity::$encoding
56+
Cannot write read-only property DOMEntity::$version

0 commit comments

Comments
 (0)