Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add interface default methods#11467

Closed
morrisonlevi wants to merge 9 commits into
php:masterphp/php-src:masterfrom
morrisonlevi:interface-default-methodsmorrisonlevi/php-src:interface-default-methodsCopy head branch name to clipboard
Closed

Add interface default methods#11467
morrisonlevi wants to merge 9 commits into
php:masterphp/php-src:masterfrom
morrisonlevi:interface-default-methodsmorrisonlevi/php-src:interface-default-methodsCopy head branch name to clipboard

Conversation

@morrisonlevi
Copy link
Copy Markdown
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
Comment thread Zend/zend_inheritance.c
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 thread Zend/zend_inheritance.c
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
Copy Markdown
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
Copy Markdown
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.

Comment thread Zend/zend_compile.h
#define ZEND_CLASS_CONST_IS_CASE (1 << 6) /* | | | X */
/* | | | */
/* Class Flags (unused: 30,31) | | | */
/* Class Flags (unused: 31). | | | */
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.