class Example{ use Trait1, Trait2, Trait3; } $reflected = new ReflectionClass('Example'); $traits = $reflected->getTraitNames(); print_r($traits);
class RandomClass{} $reflected = new ReflectionClass('RandomClass'); $traits = $reflected->getTraitNames(); print_r($traits);This example shows how to get the names of the traits used in the RandomClass class using the getTraitNames method. Since the RandomClass class doesn't use any traits, the array returned is empty. The ReflectionClass is part of the PHP core library.