Add interface default methods#11467
Add interface default methods#11467morrisonlevi wants to merge 9 commits intophp:masterphp/php-src:masterfrom morrisonlevi:interface-default-methodsmorrisonlevi/php-src:interface-default-methodsCopy head branch name to clipboard
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.
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.
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.
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.
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.
Not sure if that's really an improvement.
There was a problem hiding this comment.
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.
| #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.
Isn't flag 30 still unused? Whereas the 31 is used for strict types?
There was a problem hiding this comment.
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.