xref: /php-src/ext/reflection/tests/traits004.phpt (revision d8696f92)
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
12$classes  = ['C1', 'C2', 'C3'];
13foreach ($classes as $c) {
14    echo "class $c:\n";
15    $r = new ReflectionClass($c);
16    var_dump($r->getTraitNames());
17    var_dump($r->getTraits());
18    echo "\n";
19}
20?>
21--EXPECT--
22class C1:
23array(0) {
24}
25array(0) {
26}
27
28class C2:
29array(1) {
30  [0]=>
31  string(2) "T1"
32}
33array(1) {
34  ["T1"]=>
35  object(ReflectionClass)#1 (1) {
36    ["name"]=>
37    string(2) "T1"
38  }
39}
40
41class C3:
42array(2) {
43  [0]=>
44  string(2) "T1"
45  [1]=>
46  string(2) "T2"
47}
48array(2) {
49  ["T1"]=>
50  object(ReflectionClass)#2 (1) {
51    ["name"]=>
52    string(2) "T1"
53  }
54  ["T2"]=>
55  object(ReflectionClass)#3 (1) {
56    ["name"]=>
57    string(2) "T2"
58  }
59}
60