PHP 单例实例的 Eclipse PDT 单词补全失败
我有一个基本的单例类,类似于 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+ Space 在我的计算机上),Eclipse 告诉我“无默认建议”。我希望看到“myMethod
”作为一个选项出现,但事实并非如此。
如何才能完成单词补全工作?我需要以不同的方式配置 Eclipse 吗?我需要以不同的方式编写我的单例吗?
I have a basic singleton class, similar to the one shown in the PHP documentation:
// 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';
}
}
The code I write to get an instance of this class is:
$myExample = Example::singleton();
Using PDT, if I try to use its word completion to find the method myMethod in this instance, it fails. That is, if I type the following in the editor:
$myExample->
And immediately after the "->
", I press the key combination for word completion (Ctrl+Space on my computer), Eclipse tells me "No Default Proposals". I expect to see "myMethod
" appear as a choice, but it doesn't.
How can I make word completion work? Do I need to configure Eclipse differently? Do I need to write my singleton a different way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
注释是你的朋友
将 @return 注释添加到方法 docblock 中,Eclipse 应该能够识别这一点并提供详细的自动完成选项。
Comments are your friend
Add the @return annotation to the method docblock and eclipse should recognize that and provide detailed auto-complete choices.