8.3 - cannot set finality and visibility for method from trait at the same time
Open
Nobody has claimed this yet.
Bug
Status: Needs Triage
- Dominant language
- C
- Stars
- 40.4k
- Forks
- 8.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
Description
The following code:
<?php
trait SimpleTrait
{
private function foo() {}
}
class TraitFixtureWithFinalAndProtected
{
use SimpleTrait {
foo as final protected;
}
}
$rm = new ReflectionMethod(TraitFixtureWithFinalAndProtected::class, 'foo');
var_dump($rm->isFinal());
var_dump($rm->isPrivate());
var_dump($rm->isProtected());
var_dump($rm->isPublic());
Resulted in this output:
bool(false)
bool(true)
bool(false)
bool(false)
But I expected this output instead:
bool(true)
bool(false)
bool(true)
bool(false)
Looks like as final protected is completely ignored, does not change the method but does not throw an error either.
Related to: https://github.com/php/php-src/issues/12854
PHP Version
PHP 8.3
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 provided PHP 8.3 reproducer and compare the ReflectionMethod flags with the expected output. Trace the trait method aliasing path responsible for as final protected, then add a regression test showing that both modifiers are applied and confirm the reflected visibility and finality.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 54/100