class A { use Trait1; } class B extends A { use Trait2; } $reflection = new ReflectionClass('B'); $traits = $reflection->getTraits(); print_r($traits);
namespace MyPackage; class C { use MyTrait; } $reflection = new ReflectionClass('MyPackage\C'); $traits = $reflection->getTraits(); print_r($traits);This code declares a class C in the MyPackage namespace and uses the trait MyTrait. The ReflectionClass instance for class C is created and getTraits() returns the array of traits used by class C. This example likely belongs to a package or library with the namespace MyPackage.