Skip to content

Commit a26ec58

Browse files
authored
De-duplicate readonly property modification error message (#14972)
1 parent 551038b commit a26ec58

File tree

5 files changed

+12
-6
lines changed

5 files changed

+12
-6
lines changed

Zend/zend_execute.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,10 +889,15 @@ ZEND_COLD void zend_match_unhandled_error(const zval *value)
889889

890890
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_readonly_property_modification_error(
891891
const zend_property_info *info) {
892-
zend_throw_error(NULL, "Cannot modify readonly property %s::$%s",
892+
zend_readonly_property_modification_error_ex(
893893
ZSTR_VAL(info->ce->name), zend_get_unmangled_property_name(info->name));
894894
}
895895

896+
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_readonly_property_modification_error_ex(
897+
const char *class_name, const char *prop_name) {
898+
zend_throw_error(NULL, "Cannot modify readonly property %s::$%s", class_name, prop_name);
899+
}
900+
896901
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_readonly_property_indirect_modification_error(const zend_property_info *info)
897902
{
898903
zend_throw_error(NULL, "Cannot indirectly modify readonly property %s::$%s",

Zend/zend_execute.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ ZEND_API ZEND_COLD zval* ZEND_FASTCALL zend_undefined_index_write(HashTable *ht,
8383
ZEND_API ZEND_COLD void zend_wrong_string_offset_error(void);
8484

8585
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_readonly_property_modification_error(const zend_property_info *info);
86+
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_readonly_property_modification_error_ex(const char *class_name, const char *prop_name);
8687
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_readonly_property_indirect_modification_error(const zend_property_info *info);
8788

8889
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_invalid_class_constant_type_error(uint8_t type);

ext/date/php_date.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5946,7 +5946,7 @@ static zval *date_period_read_property(zend_object *object, zend_string *name, i
59465946
{
59475947
if (type != BP_VAR_IS && type != BP_VAR_R) {
59485948
if (date_period_is_internal_property(name)) {
5949-
zend_throw_error(NULL, "Cannot modify readonly property DatePeriod::$%s", ZSTR_VAL(name));
5949+
zend_readonly_property_modification_error_ex("DatePeriod", ZSTR_VAL(name));
59505950
return &EG(uninitialized_zval);
59515951
}
59525952
}
@@ -5958,7 +5958,7 @@ static zval *date_period_read_property(zend_object *object, zend_string *name, i
59585958
static zval *date_period_write_property(zend_object *object, zend_string *name, zval *value, void **cache_slot)
59595959
{
59605960
if (date_period_is_internal_property(name)) {
5961-
zend_throw_error(NULL, "Cannot modify readonly property DatePeriod::$%s", ZSTR_VAL(name));
5961+
zend_readonly_property_modification_error_ex("DatePeriod", ZSTR_VAL(name));
59625962
return value;
59635963
}
59645964

@@ -5968,7 +5968,7 @@ static zval *date_period_write_property(zend_object *object, zend_string *name,
59685968
static zval *date_period_get_property_ptr_ptr(zend_object *object, zend_string *name, int type, void **cache_slot)
59695969
{
59705970
if (date_period_is_internal_property(name)) {
5971-
zend_throw_error(NULL, "Cannot modify readonly property DatePeriod::$%s", ZSTR_VAL(name));
5971+
zend_readonly_property_modification_error_ex("DatePeriod", ZSTR_VAL(name));
59725972
return &EG(error_zval);
59735973
}
59745974

ext/dom/php_dom.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ zval *dom_write_property(zend_object *object, zend_string *name, zval *value, vo
392392

393393
if (hnd) {
394394
if (!hnd->write_func) {
395-
zend_throw_error(NULL, "Cannot modify readonly property %s::$%s", ZSTR_VAL(object->ce->name), ZSTR_VAL(name));
395+
zend_readonly_property_modification_error_ex(ZSTR_VAL(object->ce->name), ZSTR_VAL(name));
396396
return &EG(error_zval);
397397
}
398398

ext/xmlreader/php_xmlreader.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ zval *xmlreader_write_property(zend_object *object, zend_string *name, zval *val
150150
xmlreader_prop_handler *hnd = zend_hash_find_ptr(&xmlreader_prop_handlers, name);
151151

152152
if (hnd != NULL) {
153-
zend_throw_error(NULL, "Cannot modify readonly property %s::$%s", ZSTR_VAL(object->ce->name), ZSTR_VAL(name));
153+
zend_readonly_property_modification_error_ex(ZSTR_VAL(object->ce->name), ZSTR_VAL(name));
154154
} else {
155155
value = zend_std_write_property(object, name, value, cache_slot);
156156
}

0 commit comments

Comments
 (0)