Skip to content

8.3 - cannot set finality and visibility for method from trait at the same time #12855

@ondrejmirtes

Description

@ondrejmirtes

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: #12854

PHP Version

PHP 8.3

Operating System

No response

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions