-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix #74872 - Disambiguate the source of a trait alias when possible #2616
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
7ff5bc5
to
7d3f8a5
Compare
Please don't include NEWS patches in pull requests, conflicts emerge too quickly ... the merger does the NEWS change when they pull in the PR. |
A little more background on each commit and why they are still separate:
I'm not sure if the last one should be applied to GA branches as it will change an error message. |
I have removed the second commit because allowing a collision when the methods are aliased would still cause issues when that method is being called by it's original name in other methods of the same trait.
|
This needs a rebase as I haven't touched it for a long time. I'll try to get it up to date soon. |
Freshly rebased on 7.2. I'd like a thumbs up to merge this |
At least as implemented this breaks ABI, so can only go into 7.4. |
ZSTR_VAL(fn->common.scope->name), | ||
ZSTR_LEN(fn->common.scope->name), | ||
ZSTR_VAL(alias->trait_names[i]), | ||
ZSTR_LEN(alias->trait_names[i])) == 0) { |
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.
Can use zend_string_equals_ci here.
|
||
class Test | ||
{ | ||
use Trait1 { |
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.
What happens if we make this use Trait1, Trait3
and Trait3
also has an init method? If I'm reading your code right, it's just going to pick one of them. But I think this should be an error.
I'm wondering if an absolute trait method reference shouldn't be required when multiple traits are used in one block.
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.
Right now it still picks one of them in that case. The currrent behavior is to disambiguate when possible and keep the old behavior (pick one) when it's not possible to know. But yes, I think it's a good idea to error in those cases.
I've started porting this to 7.4 but still have to redo the opcache part. So I'll also rework that.
@pmmaga can we get a status update here please ? |
I've put up an alternative fix at #5232. |
Closed in favor of the PR above |
Link for bugsnet: https://bugs.php.net/bug.php?id=74872
Cases where two traits with a duplicate method name are added in the same use block will still be ambiguous.