Fix enum case conflict in trait binding#21771
Open
prateekbhujel wants to merge 2 commits intophp:PHP-8.4from
Open
Fix enum case conflict in trait binding#21771prateekbhujel wants to merge 2 commits intophp:PHP-8.4from
prateekbhujel wants to merge 2 commits intophp:PHP-8.4from
Conversation
Girgias
requested changes
Apr 16, 2026
Member
Girgias
left a comment
There was a problem hiding this comment.
This also needs to target 8.4 as a bug fix :) (rebase localy and force push before changing the branch on GH)
Contributor
Author
|
Updated this to target PHP-8.4 and retargeted the PR there. |
Contributor
Author
|
Sounds good, I’ll leave it as is for now and can adjust the wording if @TimWolla has a preference. |
iluuu1994
approved these changes
Apr 17, 2026
| const zend_class_entry *ce, const zend_class_constant *trait_constant, zend_string *name | ||
| ) { | ||
| zend_error_noreturn(E_COMPILE_ERROR, | ||
| "Cannot use trait %s, because constant %s conflicts with enum case %s::%s", |
Member
There was a problem hiding this comment.
Suggested change
| "Cannot use trait %s, because constant %s conflicts with enum case %s::%s", | |
| "Cannot use trait constant %s::%s as it conflicts with enum case %s::%s", |
sounds a bit less clunky.
Member
There was a problem hiding this comment.
No, the trait is what is being used, not the constant. But I agree with part of the suggestion.
Mine would be:
Cannot use trait X, because X::Up conflicts with enum case Direction::Up
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #21760.
Trait constant binding currently assumes that an existing entry in the constants table is a normal class constant. If the existing entry is an enum case with the same name, that path crashes instead of rejecting the conflict cleanly.
Reject that conflict up front during trait constant binding and cover it with a regression test.