xref: /PHP-8.0/ext/reflection/tests/traits004.phpt (revision 7aacc705)
1--TEST--
2ReflectionClass::getTraits() and ReflectionClass::getTraitNames
3--FILE--
4<?php
5trait T1 { }
6trait T2 { }
7
8class C1 { }
9class C2 { use T1; }
10class C3 { use T1; use T2; }
11
12for ($c = "C1"; $c <= "C3"; $c++) {
13    echo "class $c:\n";
14    $r = new ReflectionClass($c);
15    var_dump($r->getTraitNames());
16    var_dump($r->getTraits());
17    echo "\n";
18}
19?>
20--EXPECT--
21class C1:
22array(0) {
23}
24array(0) {
25}
26
27class C2:
28array(1) {
29  [0]=>
30  string(2) "T1"
31}
32array(1) {
33  ["T1"]=>
34  object(ReflectionClass)#1 (1) {
35    ["name"]=>
36    string(2) "T1"
37  }
38}
39
40class C3:
41array(2) {
42  [0]=>
43  string(2) "T1"
44  [1]=>
45  string(2) "T2"
46}
47array(2) {
48  ["T1"]=>
49  object(ReflectionClass)#2 (1) {
50    ["name"]=>
51    string(2) "T1"
52  }
53  ["T2"]=>
54  object(ReflectionClass)#3 (1) {
55    ["name"]=>
56    string(2) "T2"
57  }
58}
59