This is not possible for the simple reason that $this
does not exist in this context. A static method is in the context of the class, not the instance. Which $this
it will catch? Is there any? It is impossible to use any instance member within a static method. The problem is not the trait
in itself, only a consequence of what he does, so applies to anything that changes context in this way.
Otherwise, instances can access static members since there is only one instance of it.
It is possible to do so:
trait TestTraits {
public function thistraitmethod($data) {
return $data;
}
}
class ClassUsingTrait {
use TestTraits;
public static function staticmethod(ClassUsingTrait $objeto, $data) {
return $objeto->thistraitmethod($data);
}
}
$x = new ClassUsingTrait();
ClassUsingTrait::staticmethod($x, "xxx");
Behold working in the ideone. And in the repl it.. Also put on the Github for future reference.