xref: /php-src/Zend/tests/traits/gh12854.phpt (revision e679ab36)
1--TEST--
2GH-12854 (8.3 - as final trait-used method does not correctly report visibility in Reflection)
3--FILE--
4<?php
5
6trait SimpleTrait
7{
8    public function pub() {}
9    protected function prot() {}
10    private function priv() {}
11
12    public final function final1() {}
13    public final function final2() {}
14    public final function final3() {}
15}
16
17
18class Test
19{
20    use SimpleTrait {
21        pub as final;
22        prot as final;
23        priv as final;
24
25        final1 as private;
26        final2 as protected;
27        final3 as public;
28    }
29}
30
31foreach (['pub', 'prot', 'priv', 'final1', 'final2', 'final3'] as $method) {
32    echo "--- Method: $method ---\n";
33    $rm = new ReflectionMethod(Test::class, $method);
34    var_dump($rm->isFinal());
35    var_dump($rm->isPublic());
36    var_dump($rm->isProtected());
37    var_dump($rm->isPrivate());
38}
39
40?>
41--EXPECTF--
42Warning: Private methods cannot be final as they are never overridden by other classes in %s on line %d
43
44Warning: Private methods cannot be final as they are never overridden by other classes in %s on line %d
45--- Method: pub ---
46bool(true)
47bool(true)
48bool(false)
49bool(false)
50--- Method: prot ---
51bool(true)
52bool(false)
53bool(true)
54bool(false)
55--- Method: priv ---
56bool(true)
57bool(false)
58bool(false)
59bool(true)
60--- Method: final1 ---
61bool(true)
62bool(false)
63bool(false)
64bool(true)
65--- Method: final2 ---
66bool(true)
67bool(false)
68bool(true)
69bool(false)
70--- Method: final3 ---
71bool(true)
72bool(true)
73bool(false)
74bool(false)
75