-
Notifications
You must be signed in to change notification settings - Fork 7.9k
RFC: Static class #14861
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
base: master
Are you sure you want to change the base?
RFC: Static class #14861
Conversation
e7a74bc
to
15539e0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not particularly in favor of this change, but the code mostly LGTM!
@@ -1795,13 +1795,15 @@ ZEND_API void object_properties_load(zend_object *object, HashTable *properties) | |||
* calling zend_merge_properties(). */ | |||
static zend_always_inline zend_result _object_and_properties_init(zval *arg, zend_class_entry *class_type, HashTable *properties) /* {{{ */ | |||
{ | |||
if (UNEXPECTED(class_type->ce_flags & (ZEND_ACC_INTERFACE|ZEND_ACC_TRAIT|ZEND_ACC_IMPLICIT_ABSTRACT_CLASS|ZEND_ACC_EXPLICIT_ABSTRACT_CLASS|ZEND_ACC_ENUM))) { | |||
if (UNEXPECTED(class_type->ce_flags & (ZEND_ACC_STATIC|ZEND_ACC_INTERFACE|ZEND_ACC_TRAIT|ZEND_ACC_IMPLICIT_ABSTRACT_CLASS|ZEND_ACC_EXPLICIT_ABSTRACT_CLASS|ZEND_ACC_ENUM))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is repeated often enough to where it probably makes sense to extract it into a new macro. E.g. ZEND_ACC_UNINSTANTIABLE_FLAGS
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you perhaps agree this is best left for a separate refactoring PR?
@iluuu1994 Thanks so much for the (thorough) review! About half the comments pertain to @oplanre's changes, so I am unable to comment on why they were made, but nevertheless I take ownership of them now, so I will make the requested changes. Is it acceptable to rebase so changes not wanted can be as if they were never made, or should I add additional commits to revert where required? |
@Bilge Whichever you prefer. Commits can help for large PRs, but rebasing in this case seems fine. |
caa6595
to
ed7852b
Compare
Added compile-time check to enforce all methods must be declared static in a static class. Added compile-time mutual-exclusivity check for static classes marked with abstract or readonly modifiers. Added compile-time check to preclude static class inheriting from non-static class and vice-versa. Added compile-time check to preclude static class using a trait with non-static properties or methods. Fixed ZEND_ACC_IMPLICIT_ABSTRACT_CLASS collision with ZEND_ACC_STATIC.
Fix reflection test.
aaa7c9a
to
4c0d0d6
Compare
Improved a couple of static class tests per feedback.
4c0d0d6
to
23d0272
Compare
This implements static classes as described in the RFC and supersedes #14583. Static classes are implemented with the following semantics:
new
keyword.unserialize()
.new ReflectionClass()->newInstance()
).readonly
modifier.static
.abstract static
classes.ReflectionClass::isStatic()
.Thanks