Skip to content
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

Reflection: indicate final properties in string output #17827

Open
wants to merge 2 commits into
base: PHP-8.4
Choose a base branch
from

Conversation

DanielEScherzer
Copy link
Contributor

Add "final" to the result of _property_string() when outputting the string representation of a ReflectionClass or ReflectionProperty instance

@DanielEScherzer
Copy link
Contributor Author

CC @iluuu1994 - my understanding is that final properties was added as a part of property hooks

Copy link
Member

@iluuu1994 iluuu1994 left a comment

Choose a reason for hiding this comment

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

Thank you! Indeed, this was missed in the implementation. This should also add abstract, which was added in the same PR. It should also target 8.4+.

@@ -931,6 +931,9 @@ static void _property_string(smart_str *str, zend_property_info *prop, const cha
if (!prop) {
smart_str_append_printf(str, "<dynamic> public $%s", prop_name);
} else {
if (prop->flags & ZEND_ACC_FINAL) {
smart_str_appends(str, "final ");
}
Copy link
Member

Choose a reason for hiding this comment

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

Can you move this down to ZEND_ACC_STATIC? Granted, this is inconsistent with the order for methods, but final public static $prop; is weird.

The order seems to be abstract/final/static for other structures.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For me public final sounds odd, and public abstract would sound even odder - https://www.php.net/manual/en/language.oop5.abstract.php put abstract before visibility for properties, I didn't see any examples of final properties to compare with.

I tried to do a code search in github but the regex wasn't cooperating with me to match property declarations. Looking through the property hooks implementation PR, I see

  • Zend/tests/property_hooks/final_private_prop.phpt -> final private ...
  • Zend/tests/property_hooks/final_prop.phpt -> public final ...
  • Zend/tests/property_hooks/final_prop_2.phpt -> public final ...
  • Zend/tests/property_hooks/final_prop_final_hook.phpt -> final public ...
    in consecutive test files.

Without a standard practice one way or the other, I figured it was better to be consistent with methods

Add "final" to the result of `_property_string()` when outputting the string
representation of a `ReflectionClass` or `ReflectionProperty` instance
Add "abstract" to the result of `_property_string()` when outputting the string
representation of a `ReflectionClass` or `ReflectionProperty` instance
@DanielEScherzer DanielEScherzer changed the base branch from master to PHP-8.4 February 18, 2025 02:00
@DanielEScherzer
Copy link
Contributor Author

Thank you! Indeed, this was missed in the implementation. This should also add abstract, which was added in the same PR. It should also target 8.4+.

Added abstract.

I didn't send this to 8.4 originally since it isn't really a bug, but retargeted.

I was planning to also work on some kind of indication of property hooks in a follow-up, should that also go to 8.4?

@iluuu1994
Copy link
Member

I would classify this as a bug. Whether your other PR should target 8.4 depends on whether it's a bug. 😄

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.

2 participants