Collision of interface constant and trait constant doesn't produce fatal error
Open
Nobody has claimed this yet.
Bug
Category: Engine
Status: Verified
- Dominant language
- C
- Stars
- 40.4k
- Forks
- 8.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
Description
The following code:
<?php
trait MyTrait{
const A = 1;
}
interface I{
const A = 2;
}
class D implements I{
use MyTrait;
}
echo D::A;
Resulted in this output:
1
But I expected this output instead:
Fatal error: I and MyTrait define the same constant (A) in the composition of D. However, the definition differs and is considered incompatible. Class was composed in /in/EVuKh on line 10
PHP Version
8.2
Operating System
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the PHP 8.2 reproduction script from the issue and confirm that the trait and interface constants resolve to 1 instead of producing an error. Trace the trait/interface constant composition for class D, then add a regression test showing the expected fatal error and verify the existing behavior is preserved for compatible definitions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100