Skip to content

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

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jiripudil
Copy link

Comment on lines +6 to +7
class C
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class C
{
class C {

to match the other tests

@@ -0,0 +1,19 @@
--TEST--
#[\Override]: Properties: On used trait without parent method.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[\Override]: Properties: On used trait without parent method.
#[\Override]: Properties: On used trait without parent property.

@@ -0,0 +1,23 @@
--TEST--
#[\Override]: Properties: On used trait with interface method.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[\Override]: Properties: On used trait with interface method.
#[\Override]: Properties: On used trait with interface property.

@@ -0,0 +1,19 @@
--TEST--
#[\Override]: Properties: Parent property is private (2).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the tests where this is a (2) version, I suggest identifying what the difference is, e.g.

#[\Override]: Property: Parent property is private (child property public)
#[\Override]: Property: Parent property is private (child property private)

@@ -7881,6 +7881,11 @@ static void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32
zend_compile_attributes(
&prop->attributes, attributes_ast, 0, ZEND_ATTRIBUTE_TARGET_PROPERTY, ZEND_ATTRIBUTE_TARGET_PARAMETER);
}

zend_attribute *override_attribute = zend_get_attribute_str(prop->attributes, "override", sizeof("override")-1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking for the override attribute should only be needed if the property has any attributes, i.e. this can be moved into the if (attributes_ast) { conditional block

@@ -8859,6 +8864,11 @@ static void zend_compile_prop_decl(zend_ast *ast, zend_ast *type_ast, uint32_t f
zend_compile_attributes(&info->attributes, attr_ast, 0, ZEND_ATTRIBUTE_TARGET_PROPERTY, 0);
}

zend_attribute *override_attribute = zend_get_attribute_str(info->attributes, "override", sizeof("override")-1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above, check is only needed if the attr_ast check passes

Comment on lines +1570 to +1572
if (child_info->flags & ZEND_ACC_OVERRIDE) {
child_info->flags &= ~ZEND_ACC_OVERRIDE;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can just unconditionally try to remove the flag:

Suggested change
if (child_info->flags & ZEND_ACC_OVERRIDE) {
child_info->flags &= ~ZEND_ACC_OVERRIDE;
}
child_info->flags &= ~ZEND_ACC_OVERRIDE;

Comment on lines +2328 to +2335
ZEND_HASH_MAP_FOREACH_PTR(&ce->properties_info, p) {
if (p->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(p->name));
}
} ZEND_HASH_FOREACH_END();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can probably merged with the loop below (by removing the ce->num_hooked_props check).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants