From 442f9818d8b3fddf5dd9c1411913923986d628a2 Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Tue, 16 Jul 2024 12:19:58 +0200 Subject: [PATCH] De-duplicate readonly property modification error message --- Zend/zend_execute.c | 7 ++++++- Zend/zend_execute.h | 1 + ext/date/php_date.c | 6 +++--- ext/dom/php_dom.c | 2 +- ext/xmlreader/php_xmlreader.c | 2 +- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 084625ba0c4d2..c0e428fb0eca5 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -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", diff --git a/Zend/zend_execute.h b/Zend/zend_execute.h index 027cdad062b88..fe854f305150c 100644 --- a/Zend/zend_execute.h +++ b/Zend/zend_execute.h @@ -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); diff --git a/ext/date/php_date.c b/ext/date/php_date.c index da4606a93c1d9..8a77974b8b905 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -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); } } @@ -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; } @@ -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); } diff --git a/ext/dom/php_dom.c b/ext/dom/php_dom.c index 3d7dfe3439fef..984d46cb7d3a0 100644 --- a/ext/dom/php_dom.c +++ b/ext/dom/php_dom.c @@ -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); } diff --git a/ext/xmlreader/php_xmlreader.c b/ext/xmlreader/php_xmlreader.c index a92d45ace6547..4444d3f83a389 100644 --- a/ext/xmlreader/php_xmlreader.c +++ b/ext/xmlreader/php_xmlreader.c @@ -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); }