我有一个基本的单例类,类似于PHP文档中所示的那个:
// Based on "Example #2 Singleton Function" from
// www.php.net/manual/en/language.oop5.patterns.php
class Example {
private static $instance;
private function __construct() {
echo 'I am constructed';
}
public static function singleton() {
if (!isset(self::$instance)) {
$c = __CLASS__;
self::$instance = new $c;
}
return self::$instance;
}
public function myMethod() {
echo 'This is my method';
}
}
我为获取此类的实例而编写的代码是:
$myExample = Example::singleton();
使用 PDT,如果我尝试使用其单词完成来查找本例中的方法 myMethod,它将失败。 也就是说,如果我在编辑器中键入以下内容:
$myExample->
紧接着" ->
",我按下组合键进行单词完成(计算机上的 Ctrl+空格键),Eclipse 告诉我"没有默认建议"。 我希望看到"myMethod
"作为一种选择出现,但它没有。
如何使单词完成工作? 我是否需要以不同的方式配置 Eclipse? 我需要以不同的方式编写我的单例吗?
评论是你的朋友
/**
*
* @return Example
*/
public static function singleton() {
if (!isset(self::$instance)) {
$c = __CLASS__;
self::$instance = new $c;
}
return self::$instance;
}
将@return注释添加到方法docblock和eclipse应该识别并提供详细的自动完成选项。