I have a trait. For the sake of creativity, let's call this trait Trait:
trait Trait{
static function treat($instance){
// treat that trait instance with care
}
}
Now, I also have a class that uses this trait, User. When trying to call treat with an instance of User, everything works. But I would like to type-hint that only instances of classes using Trait should be given as arguments, like that:
static function treat(Trait $instance){...}
Sadly, though, this results in a fatal error that says the function was expecting an instance of Trait, but an instance of User was given. That type of type-hinting works perfectly for inheritance and implementation, but how do I type-hint a trait?
use
statements to implement traits as they are not instantiated. – phpisuber01wtf
see eval.in/5936 if its not going to be treated as a class why are you gettingFatal error: Cannot redeclare class Hello
– Baba