Skip to content

Instantly share code, notes, and snippets.

@carlescliment
Created April 3, 2014 09:06
Show Gist options
  • Save carlescliment/9951042 to your computer and use it in GitHub Desktop.
Save carlescliment/9951042 to your computer and use it in GitHub Desktop.
class_uses does not work on subclasses
Trait SomeTrait
{
}
class A
{
use SomeTrait;
}
class B extends A
{
}
var_dump(class_uses(new A));
var_dump(class_uses(new B));
// The output is:
array(1) {
["SomeTrait"]=>
string(9) "SomeTrait"
}
array(0) {
}
@carlescliment
Copy link
Author

DIrectly from the php documentation:

This function returns an array with the names of the traits that the given class uses. This does however not include any traits used by a parent class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment