Type hint multiple interfaces in PhpStorm

While working in PhpStorm I came across the necessity to type hint, read “get auto-completion”, for methods of an object implementing 2 classes.

The problem

With interfaces like

interface InterfaceOne{ public function methodOne(); } interface InterfaceTwo{ public function methodTwo(); } 

I might be using an object implementing both interfaces and be willing to keep the type-hinting interface-based in the code like this

class AnotherClass { protected $object; public function method(){ $this->object->... } } 

To make the auto-complete magic unleash its full potential I need to define the class or interface $object extends/implements using the @var annotation

 class AnotherClass { /** * @var InterfaceOne */ protected $object; public function method(){ $this->object->... } } 

and PhpStorm will properly auto-complete the methodOne method. But what if $object implements both interfaces and I want to get method auto-completion for InterfaceTwo::methodTwo too?

The slick solution

Keeping in mind that I do not want to type hint a concrete or abstract class I can tell PhpStorm $object implements both interfaces like this

 class AnotherClass { /** * @var InterfaceOne|InterfaceTwo */ protected $object; public function method(){ $this->object->... } 

and will get auto-completion for both, brilliant.

I appreciate your input