I have a trait and would like to type hint $this to inform the compiler of it's type:
trait MyTrait {
public function myAwesomeFunction() {
return new OtherClass($this); // warning: Expected MyAwesomeInterface, got MyTrait
}
}
class OtherClass {
public function __construct(MyAwesomeInterface $foo) { ... }
}
So I wonder if there is something equivalent to, e.g.:
trait MyTrait {
public function myAwesomeFunction() {
/**
* @var $this MyAwesomeInterface
*/
return new OtherClass($this); // no warnings
}
}
That would allow me to inform the compiler that users of the trait implement my interface.
Note that a trait cannot implement an interface in PHP (see Why PHP Trait can't implement interfaces?).
Thank you for any help ;-)