Skip to content

De-duplicate readonly property modification error message #14972

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
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
7 changes: 6 additions & 1 deletion Zend/zend_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -889,10 +889,15 @@ ZEND_COLD void zend_match_unhandled_error(const zval *value)

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

ZEND_API ZEND_COLD void ZEND_FASTCALL zend_readonly_property_modification_error_ex(
const char *class_name, const char *prop_name) {
zend_throw_error(NULL, "Cannot modify readonly property %s::$%s", class_name, prop_name);
}

ZEND_API ZEND_COLD void ZEND_FASTCALL zend_readonly_property_indirect_modification_error(const zend_property_info *info)
{
zend_throw_error(NULL, "Cannot indirectly modify readonly property %s::$%s",
Expand Down
1 change: 1 addition & 0 deletions Zend/zend_execute.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ ZEND_API ZEND_COLD zval* ZEND_FASTCALL zend_undefined_index_write(HashTable *ht,
ZEND_API ZEND_COLD void zend_wrong_string_offset_error(void);

ZEND_API ZEND_COLD void ZEND_FASTCALL zend_readonly_property_modification_error(const zend_property_info *info);
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_readonly_property_modification_error_ex(const char *class_name, const char *prop_name);
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_readonly_property_indirect_modification_error(const zend_property_info *info);

ZEND_API ZEND_COLD void ZEND_FASTCALL zend_invalid_class_constant_type_error(uint8_t type);
Expand Down
6 changes: 3 additions & 3 deletions ext/date/php_date.c
Original file line number Diff line number Diff line change
Expand Up @@ -5946,7 +5946,7 @@ static zval *date_period_read_property(zend_object *object, zend_string *name, i
{
if (type != BP_VAR_IS && type != BP_VAR_R) {
if (date_period_is_internal_property(name)) {
zend_throw_error(NULL, "Cannot modify readonly property DatePeriod::$%s", ZSTR_VAL(name));
zend_readonly_property_modification_error_ex("DatePeriod", ZSTR_VAL(name));
return &EG(uninitialized_zval);
}
}
Expand All @@ -5958,7 +5958,7 @@ static zval *date_period_read_property(zend_object *object, zend_string *name, i
static zval *date_period_write_property(zend_object *object, zend_string *name, zval *value, void **cache_slot)
{
if (date_period_is_internal_property(name)) {
zend_throw_error(NULL, "Cannot modify readonly property DatePeriod::$%s", ZSTR_VAL(name));
zend_readonly_property_modification_error_ex("DatePeriod", ZSTR_VAL(name));
return value;
}

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

Expand Down
2 changes: 1 addition & 1 deletion ext/dom/php_dom.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ zval *dom_write_property(zend_object *object, zend_string *name, zval *value, vo

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

Expand Down
2 changes: 1 addition & 1 deletion ext/xmlreader/php_xmlreader.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ zval *xmlreader_write_property(zend_object *object, zend_string *name, zval *val
xmlreader_prop_handler *hnd = zend_hash_find_ptr(&xmlreader_prop_handlers, name);

if (hnd != NULL) {
zend_throw_error(NULL, "Cannot modify readonly property %s::$%s", ZSTR_VAL(object->ce->name), ZSTR_VAL(name));
zend_readonly_property_modification_error_ex(ZSTR_VAL(object->ce->name), ZSTR_VAL(name));
} else {
value = zend_std_write_property(object, name, value, cache_slot);
}
Expand Down
Loading