脚本宝典收集整理的这篇文章主要介绍了php – 使用singleton检索对象而不是new运算符时netbeans自动完成?,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
$instance = new Singleton(); $instance-> // shows test() method
但是当我使用单例来检索对象时,它无法自动完成检索对象中的成员.
getInstance代码如下所示:
public function test() { echo "hello"; } public static function getInstance() { if ( ! is_object(self::$_instance)) { self::$_instance = new self(); self::$_instance->inITialize(); } return self::$_instance; }
所以我使用:
$instance = Singleton::getInstance(); $instance-> // no autocompletion!
有没有人有同样的问题?
我该如何解决这个问题?
谢谢!
/* @VAR $instance Singleton */ $instance = Singleton::getInstance();
你会得到自动完成:
http://extern.pascal-martin.fr/so/question-2796730-netbeans.png
(最近每晚建立的netbeans测试)
另一种解决方案是在getInstance()方法的声明中添加一个docblock,以指示它返回Singleton类的实例:
/** * @return Singleton */ public static function getInstance() { }
http://extern.pascal-martin.fr/so/question-2796730-netbeans-2.png
以上是脚本宝典为你收集整理的php – 使用singleton检索对象而不是new运算符时netbeans自动完成?全部内容,希望文章能够帮你解决php – 使用singleton检索对象而不是new运算符时netbeans自动完成?所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。