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--EXPECT-- 20class C1: 21array(0) { 22} 23array(0) { 24} 25 26class C2: 27array(1) { 28 [0]=> 29 string(2) "T1" 30} 31array(1) { 32 ["T1"]=> 33 object(ReflectionClass)#1 (1) { 34 ["name"]=> 35 string(2) "T1" 36 } 37} 38 39class C3: 40array(2) { 41 [0]=> 42 string(2) "T1" 43 [1]=> 44 string(2) "T2" 45} 46array(2) { 47 ["T1"]=> 48 object(ReflectionClass)#2 (1) { 49 ["name"]=> 50 string(2) "T1" 51 } 52 ["T2"]=> 53 object(ReflectionClass)#3 (1) { 54 ["name"]=> 55 string(2) "T2" 56 } 57} 58