Skip to content

8.3 - as final trait-used method does not correctly report visibility in Reflection #12854

Closed
@ondrejmirtes

Description

@ondrejmirtes

Description

The following code:

<?php

trait SimpleTrait
{
    private function foo() {}
}


class TraitFixtureWithFinal
{
    use SimpleTrait {
        foo as final;
    }
}

$rm = new ReflectionMethod(TraitFixtureWithFinal::class, 'foo');
var_dump($rm->isFinal());
var_dump($rm->isPrivate());
var_dump($rm->isPublic());
var_dump($rm->isProtected());

Resulted in this output:

bool(true)
bool(false)
bool(false)
bool(false)

But I expected this output instead:

bool(true)
bool(true)
bool(false)
bool(false)

Alternatively, a syntax resulting in "final private" class method should be rejected because normally they're not allowed.

But the same bug applies to "protected" method - isProtected in ReflectionMethod is also false: https://3v4l.org/0PZvm#v8.3.0

PHP Version

PHP 8.3

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions