Method returns an instance of the class
Hi,
The framework I'm using contains an abstract implementation for singletons (attached here) called `SingletonFactory`. When calling the method `getInstance` on any child member an instance of the class (not the `SingletonFactory`-class) is returned.
class ABC extends SingletonFactory {
public function bla() {
// do something
}
}
ABC::getInstance()->bla();
Unfortunately PhpStorm assumes (based on the PhpDoc) that an instance of `SingletonFactory` is returned. Is there any way to fix this? (Possible without changing the class itself?)
Thanks,
Magnus
Attachment(s):
SingletonFactory.class.php.zip
请先登录再写评论。
Hi there,
Please use @return static instead (in original SingletonFactory class). @return $this should also work.
Without modifying original code of your framework -- only this way, unfortunately -- via intermediate variable:
P.S.
Correct way of declaring such typed array is:
HI,
Thank you for your response. It's not mine framework and therefor not my fault ;).
Adding "@return static" to the class works perfectly together with telling git to ignore the file change. (git update-index --assume-unchanged)
Magnus