Skip to content

Add ReflectionProperty::isDynamic() as an alternative to isDefault() #15758

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
merged 3 commits into from
Sep 11, 2024

Conversation

DanielEScherzer
Copy link
Member

Dynamic properties are generally referred to as "dynamic" properties, while non-dynamic properties are not commonly referred to as "default" properties. Thus, the existing method ReflectionProperty::isDefault() has a non obvious name; while an alias could be added for isNotDynamic(), a new isDynamic() method seems cleaner. The new method returns the opposite of isDefault(); dynamic properties are not present on the class by default, and properties present by default are not added dynamically.

Closes GH-15754

@cmb69
Copy link
Member

cmb69 commented Sep 5, 2024

Thank you!

Since this is a new feature and we're already in beta stage, this likely needs RM approval.

@@ -5921,8 +5921,7 @@ ZEND_METHOD(ReflectionProperty, isVirtual)
_property_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_VIRTUAL);
}

/* {{{ Returns whether this property is default (declared at compilation time). */
ZEND_METHOD(ReflectionProperty, isDefault)
static void _property_check_dynamic(INTERNAL_FUNCTION_PARAMETERS, bool dynamicTrue) /* {{{ */
Copy link
Member

Choose a reason for hiding this comment

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

nit: feel free to omit the {{{ and /* }}} */ tags

Copy link
Member

Choose a reason for hiding this comment

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

This parameter name is more in line with the conventions:

Suggested change
static void _property_check_dynamic(INTERNAL_FUNCTION_PARAMETERS, bool dynamicTrue) /* {{{ */
static void _property_check_dynamic(INTERNAL_FUNCTION_PARAMETERS, bool is_dynamic) /* {{{ */

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that might get confusing since I use isDynamic to hold the result of checking if the property is dynamic a few lines lower down - how about dynamic_true?

Copy link
Member

Choose a reason for hiding this comment

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

Hm, ok, it's ok as long as you consistently use the camel_case style ^^ At least, most code in php-src uses this convention so the camelCase looks a bit weird for me here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Isn't camelCase with the capitals, and snake_case what is used?

Copy link
Member

Choose a reason for hiding this comment

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

Isn't camelCase with the capitals, and snake_case what is used?

Sorry, I'm not in my sharpest form today

Copy link
Member

Choose a reason for hiding this comment

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

And again, thank you, I support this feature very much, the original method name is very misleading. I'd say that the change is pretty much self contained, but RMs should approve it nevertheless. Please also write an upgrading note once you have the green light.

@Girgias
Copy link
Member

Girgias commented Sep 9, 2024

This feature is small and self-contained and should be approved by RMs @php/release-managers-84

Copy link
Member

@NattyNarwhal NattyNarwhal left a comment

Choose a reason for hiding this comment

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

OK to merge, this seems simple enough

@kocsismate
Copy link
Member

@DanielEScherzer Now, only the UPGRADING note is missing before I can merge this :)

Dynamic properties are generally referred to as "dynamic" properties, while
non-dynamic properties are not commonly referred to as "default" properties.
Thus, the existing method `ReflectionProperty::isDefault()` has a non obvious
name; while an alias could be added for `isNotDynamic()`, a new `isDynamic()`
method seems cleaner. The new method returns the opposite of `isDefault()`;
dynamic properties are not present on the class by default, and properties
present by default are not added dynamically.

Closes phpGH-15754
@DanielEScherzer
Copy link
Member Author

@DanielEScherzer Now, only the UPGRADING note is missing before I can merge this :)

Done, along with a rebase so that there wouldn't be merge conflicts

@kocsismate kocsismate merged commit 2ced1c9 into php:master Sep 11, 2024
10 checks passed
@kocsismate
Copy link
Member

Thank you!

@DanielEScherzer DanielEScherzer deleted the reflection-dynamic branch September 11, 2024 16:17
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.

Add ReflectionProperty::isDynamic as a more obvious alternative to ReflectionProperty::isDefault
5 participants