Skip to content

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

Closed

Conversation

morrisonlevi
Copy link
Contributor

This is a proof of concept implementation for https://wiki.php.net/rfc/interface-default-methods.

@morrisonlevi morrisonlevi force-pushed the interface-default-methods branch from a233969 to 9dc6b72 Compare June 20, 2023 04:23
@morrisonlevi morrisonlevi force-pushed the interface-default-methods branch from 13bfd7d to 730179d Compare June 21, 2023 19:06
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));
Copy link
Contributor Author

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();
Copy link
Member

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

Comment on lines +16 to +17
(new Class1())->method1();

Copy link
Member

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
Copy link
Member

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.

Comment on lines +1166 to +1169
/* 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)) {
Copy link
Member

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.

Copy link
Contributor Author

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). | | | */
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 flag 30 still unused? Whereas the 31 is used for strict types?

Copy link
Contributor Author

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.

@morrisonlevi
Copy link
Contributor Author

Closing due to a declined RFC.

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