xref: /PHP-8.3/Zend/tests/traits/bugs/gh13177.phpt (revision c2c1710e)
1--TEST--
2GH-13177 (PHP 8.3.2: final private constructor not allowed when used in trait)
3--FILE--
4<?php
5
6trait Bar {
7    final private function __construct() {}
8}
9
10final class Foo1 {
11    use Bar;
12}
13
14final class Foo2 {
15    use Bar {
16        __construct as final;
17    }
18}
19
20class Foo3 {
21    use Bar {
22        __construct as final;
23    }
24}
25
26trait TraitNonConstructor {
27    private final function test() {}
28}
29
30class Foo4 {
31    use TraitNonConstructor { test as __construct; }
32}
33
34for ($i = 1; $i <= 4; $i++) {
35    $rc = new ReflectionClass("Foo$i");
36    echo $rc->getMethod("__construct"), "\n";
37}
38
39class Foo5 extends Foo3 {
40    private function __construct() {}
41}
42
43?>
44--EXPECTF--
45Warning: Private methods cannot be final as they are never overridden by other classes in %s on line %d
46Method [ <user, ctor> final private method __construct ] {
47  @@ %sgh13177.php 4 - 4
48}
49
50Method [ <user, ctor> final private method __construct ] {
51  @@ %sgh13177.php 4 - 4
52}
53
54Method [ <user, ctor> final private method __construct ] {
55  @@ %sgh13177.php 4 - 4
56}
57
58Method [ <user, ctor> final private method __construct ] {
59  @@ %sgh13177.php 24 - 24
60}
61
62
63Fatal error: Cannot override final method Foo3::__construct() in %s on line %d
64