-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add interface default methods #11467
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
Conversation
a233969
to
9dc6b72
Compare
13bfd7d
to
730179d
Compare
730179d
to
c819e2d
Compare
ZEND_ASSERT(!((fe->common.fn_flags & ZEND_ACC_CTOR) | ||
&& ((proto->common.scope->ce_flags & ZEND_ACC_INTERFACE) == 0 | ||
&& (proto->common.fn_flags & ZEND_ACC_ABSTRACT) == 0))); | ||
ZEND_ASSERT(!(fe->common.fn_flags & ZEND_ACC_CTOR) || !is_abstract_or_interface_method(proto)); |
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.
Note to self: double-check this change. Tests didn't fail for me, but that's no guarantee.
function method1() { parent::method1(); } | ||
} | ||
|
||
(new Class1())->method1(); |
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 test is wrong, you should be calling the method on an instance of Class2
(new Class1())->method1(); | ||
|
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.
Shouldn't this test a static call? Or ideally both?
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: Type Class1 already has default method Interface1::method1(); cannot override it with another from Interface2 in %s on line %d |
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.
The error message probably should be better here.
/* Prevent derived classes from restricting access that was available in parent classes | ||
* (except deriving from non-abstract ctors). */ | ||
uint32_t ppp_mask = ZEND_ACC_PPP_MASK; | ||
if (!checked && check_visibility && (child_flags & ppp_mask) > (parent_flags & ppp_mask)) { |
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.
Not sure if that's really an improvement.
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.
An earlier version used ppp_mask
in more places, but eventually they were removed. In that context, it makes sense, but as things stand now, I agree, let's revert this part.
@@ -238,7 +238,7 @@ typedef struct _zend_oparray_context { | |||
/* or IS_CONSTANT_VISITED_MARK | | | */ | |||
#define ZEND_CLASS_CONST_IS_CASE (1 << 6) /* | | | X */ | |||
/* | | | */ | |||
/* Class Flags (unused: 30,31) | | | */ | |||
/* Class Flags (unused: 31). | | | */ |
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.
Isn't flag 30 still unused? Whereas the 31 is used for strict types?
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 had some wonkery when fixing a merge conflict and I was quite tired. I'll revisit today with fresh eyes. Thanks for your review.
Closing due to a declined RFC. |
This is a proof of concept implementation for https://wiki.php.net/rfc/interface-default-methods.