[RFC] Extend #[\Override] to target properties (#19061)

RFC: https://wiki.php.net/rfc/override_properties

Co-authored-by: Tim Düsterhus <tim@bastelstu.be>
This commit is contained in:
Jiří Pudil 2025-08-12 15:18:50 +02:00 committed by GitHub
parent c3bee21256
commit 38beb44176
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
27 changed files with 449 additions and 19 deletions

View file

@ -1563,6 +1563,8 @@ static void do_inherit_property(zend_property_info *parent_info, zend_string *ke
ZSTR_VAL(key),
ZSTR_VAL(parent_info->ce->name));
}
child_info->flags &= ~ZEND_ACC_OVERRIDE;
}
} else {
zend_function **hooks = parent_info->hooks;
@ -2315,13 +2317,11 @@ static void zend_do_implement_interfaces(zend_class_entry *ce, zend_class_entry
void zend_inheritance_check_override(const zend_class_entry *ce)
{
zend_function *f;
if (ce->ce_flags & ZEND_ACC_TRAIT) {
return;
}
ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, f) {
ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, zend_function *f) {
if (f->common.fn_flags & ZEND_ACC_OVERRIDE) {
ZEND_ASSERT(f->type != ZEND_INTERNAL_FUNCTION);
@ -2332,14 +2332,17 @@ void zend_inheritance_check_override(const zend_class_entry *ce)
}
} ZEND_HASH_FOREACH_END();
if (ce->num_hooked_props) {
zend_property_info *prop;
ZEND_HASH_MAP_FOREACH_PTR(&ce->properties_info, prop) {
if (!prop->hooks) {
continue;
}
ZEND_HASH_MAP_FOREACH_PTR(&ce->properties_info, zend_property_info *prop) {
if (prop->flags & ZEND_ACC_OVERRIDE) {
zend_error_noreturn(
E_COMPILE_ERROR,
"%s::$%s has #[\\Override] attribute, but no matching parent property exists",
ZSTR_VAL(ce->name), zend_get_unmangled_property_name(prop->name));
}
if (prop->hooks) {
for (uint32_t i = 0; i < ZEND_PROPERTY_HOOK_COUNT; i++) {
f = prop->hooks[i];
zend_function *f = prop->hooks[i];
if (f && f->common.fn_flags & ZEND_ACC_OVERRIDE) {
ZEND_ASSERT(f->type != ZEND_INTERNAL_FUNCTION);
@ -2349,8 +2352,8 @@ void zend_inheritance_check_override(const zend_class_entry *ce)
ZEND_FN_SCOPE_NAME(f), ZSTR_VAL(f->common.function_name));
}
}
} ZEND_HASH_FOREACH_END();
}
}
} ZEND_HASH_FOREACH_END();
}