Skip to content

Bind traits before parent class #15878

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
wants to merge 3 commits into from
Closed

Conversation

iluuu1994
Copy link
Member

@iluuu1994 iluuu1994 commented Sep 13, 2024

This more accurately matches the "copy & paste" semantics described in
the documentation. Abstract trait methods diverge from this behavior,
given that a parent method can satisfy trait methods used in the child.
In that case, the method is not copied, but the check is performed after
the parent has been bound.

Fixes GH-15753
Fixes GH-16198

Copy link
Member

@dstogov dstogov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't know if this change is OK or not and what subsequences it may make.

@cmb69
Copy link
Member

cmb69 commented Oct 8, 2024

A couple of weeks ago I would have suggested to apply this master only, but now I'm unsure whether it should still go into PHP-8.4. Maybe the @php/release-managers-84 want to have a look.

@NattyNarwhal
Copy link
Member

I'm also unsure about this myself. This late and this ambiguous, I think it'd be better off in 8.5.

@iluuu1994
Copy link
Member Author

Can you explain what you mean by ambiguous? It might be good to adjust methods too, which should make behavior consistent and predictable. But it might require a bit more changes.

@NattyNarwhal
Copy link
Member

I was referring to Dmitry's comment about possible fallout.

@iluuu1994
Copy link
Member Author

Ok, thanks for the clarification. I will make the changes for methods, and then target this to master.

@iluuu1994 iluuu1994 changed the base branch from PHP-8.2 to master October 14, 2024 17:44
@iluuu1994 iluuu1994 changed the title Bind trait props/consts before parent class Bind traits before parent class Mar 27, 2025
This more accurately matches the "copy & paste" semantics described in
the documentation. Abstract trait methods diverge from this behavior,
given that a parent method can satisfy trait methods used in the child.
In that case, the method is not copied, but the check is performed after
the parent has been bound.

Fixes phpGH-15753
Fixes phpGH-16198
zend_add_trait_method() never overrides a parent method, given that
parents are not bound yet. Instead, compatibility is checked in
do_inherit_method(), as per usual.
Copy link
Member

@TimWolla TimWolla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't say I fully understand the implementation, due to my lack of familiarity with the code. The test changes however make sense to me, so this definitely is a LGTM in concept.

I'm particularly happy about the workaround in d344fe0 going away.

I've some minor inline comments about the implementation.

@TimWolla
Copy link
Member

TimWolla commented Apr 1, 2025

For reference, #14148 is somewhat related to this as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants