Skip to content

Changing trait provided final protected method to private results in warning #17214

@cs278

Description

@cs278

Description

The following code:

<?php

trait MyTrait
{
    final protected function someMethod(): void {}
}

class Test
{
    use MyTrait {
        someMethod as private anotherMethod;
    }
    
    public function __construct()
    {
        $this->anotherMethod();
    }
}

Resulted in this output:

Warning: Private methods cannot be final as they are never overridden by other classes in /in/YtW3h on line 8

But I expected this output instead:

No error

https://3v4l.org/YtW3h

PHP Version

8.3.14 and 8.4.1

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions