Skip to content

PHP 8.3.2: final private constructor not allowed when used in trait #13177

Closed
@ondrejmirtes

Description

@ondrejmirtes

Description

The following code:

<?php

final class Foo {
    
    use Bar;
}

trait Bar {
    
    final private function __construct() {}
    
}

Resulted in this output:

Warning: Private methods cannot be final as they are never overridden by other classes in /in/4sc3H on line 3

But I expected this output instead:

No error

Constructors CAN be private AND final, as opposed to normal methods.

This is a wrong side effect of this fix: #12857

Please make sure that the version with trait usage is also allowed:

<?php

final class Foo {
    
    use Bar {
        __construct as final;
    }
}

trait Bar {
    
    private function __construct() {}
    
}

PHP Version

PHP 8.3.2

Operating System

N/A

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions