Hi guys. To use correct autocomplete and type highlighting in IDE, like PhpStorm let's use static keyword instead of class name in @return block.
In this case IDE will notify us that methodFromB() doesn't exist, because it will expect that method iWillReturnThis returns class A:
class A {
/**
* @return A
*/
public function iWillReturnThis() {
return $this;
}
}
class B extends A {
public function methodFromB() { }
}
(new B())->iWillReturnThis()->methodFromB()
In this case it works well:
class A {
/**
* @return static
*/
public function iWillReturnThis() {
return $this;
}
}
...
And to make fluent interface highlighting works well with public properties, let's use phpDoc @var near property declaration, like:
class A {
/** @var B */
public $B;
}
class B {
public function method();
}
(new A())->B->method()
… which returns $this.
Hi guys. To use correct autocomplete and type highlighting in IDE, like PhpStorm let's use
static
keyword instead of class name in@return
block.In this case IDE will notify us that
methodFromB()
doesn't exist, because it will expect that methodiWillReturnThis
returns classA
:In this case it works well:
And to make fluent interface highlighting works well with
public
properties, let's use phpDoc@var
near property declaration, like: