megacolorboy

Back

Published on March 12th, 2021

PHP

Check if trait is being used in your class

Want to know if a trait is being used in your current class? Try this:By any chance, if the current class is inherited, please note that the method will only return the list of traits used by the current class and won't include any traits of it's parent class.

1 minute read

Want to know if a trait is being used in your current class? Try this:


in_array(Foo::class, class_uses($this))

By any chance, if the current class is inherited, please note that the class_uses() method will only return the list of traits used by the current class and won't include any traits of it's parent class.