简体   繁体   English

Eclipse PHP 代码提示问题

[英]Eclipse PHP code hinting question

Is there a way to make Eclipse give code hints to variables created from objects?有没有办法让 Eclipse 为从对象创建的变量提供代码提示? For example if I create a new variable:例如,如果我创建一个新变量:

$db = new mysqli('server', 'user', 'pwd', 'database');

then $db-> brings up code hints, but if I do:然后$db->显示代码提示,但如果我这样做:

$query = 'Select * From thisTable';
$result = $db->query($query);

but then if I use:但是如果我使用:

$result->

I do not get any code hints.. I'm pretty new to Eclipse and PHP.我没有得到任何代码提示。我对 Eclipse 和 PHP 还是很陌生。 I have searched around but could not find anything related to this.我四处搜寻,但找不到与此相关的任何内容。 I did notice while trying out the new version of Dreamweaver CS5.5 it does do code hinting for the above scenario.我在试用 Dreamweaver CS5.5 的新版本时确实注意到它确实为上述场景提供了代码提示。

Most PHP IDEs rely (mainly) on the PHPDoc when computing the code assist suggestions.大多数 PHP IDE 在计算代码辅助建议时(主要)依赖于 PHPDoc。 This is quite a must for dynamic languages such as PHP, since the type-binding is very 'flexible'.这对于诸如 PHP 之类的动态语言来说是非常必要的,因为类型绑定非常“灵活”。

You may hit some limitations in the IDE capability to assist you in some cases (such as the case you defined).您可能会遇到 IDE 功能在某些情况下(例如您定义的情况)为您提供帮助的一些限制。 In these cases, some IDE's provide mechanisms to specifically the variable type.在这些情况下,某些 IDE 提供了专门针对变量类型的机制。 In your case, the returned type is 'mixed' (see php.net), so you have to define what it is.在您的情况下,返回的类型是“混合”(参见 php.net),因此您必须定义它是什么。

It might be hard to find out in this specific case, but in general, this is how you hint the IDE with a variable type.在这种特定情况下可能很难找到,但总的来说,这就是您如何使用变量类型提示 IDE。

In PDT:在 PDT 中:

$a = callSomeFunction();
/* @var $a PDO */
$a -> // will give you the PDO code assist for $a

Other IDEs also have similar capabilities.其他 IDE 也具有类似的功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM