Netbeans (PHP) 中的变量类型提示
只是好奇 Netbeans 中是否有一种方法可以为常规变量提供类型提示,以便智能感知能够识别它。我知道你可以对类属性、函数参数、返回类型等执行此操作,但我不知道如何对常规变量执行此操作。当您有一个可以返回不同对象类型(如服务定位器)的方法时,这确实很有帮助。
例如:
/**
* @var Some_Service $someService
*/
$someService = ServiceLocator::locate('someService');
如果之后使用 $someService,netbeans 将提供 Some_Service 类中定义的所有可用方法。
Just curious if there's a way in netbeans to give type hints for regular variables, so that intellisense picks it up. I know you can do it for class properties, function parameters, return types, etc. but I can't figure out how to do it for regular variables. It's something that would really help in situations where you have a method that can return different object types (like a service locator).
ex something like:
/**
* @var Some_Service $someService
*/
$someService = ServiceLocator::locate('someService');
Where using $someService afterward, netbeans would provide all available methods defined in the class Some_Service.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您只需要一行即可:
请参阅 NetBeans PHP 博客中的这篇文章:https://blogs。 oracle.com/netbeansphp/entry/defining_a_variable_type_in
A single line is all you need:
See this article in the NetBeans PHP Blog: https://blogs.oracle.com/netbeansphp/entry/defining_a_variable_type_in
我知道这是一个较旧的问题,但我一直在为 Eclipse/Zend Studio 寻找类似的答案,这也解决了它。
**但请注意,它必须在单行上,并以这种样式明确打开和关闭...
没有其他格式,无论...
或...
似乎都可以工作。希望对某人有帮助。
I know this is an older question, but I was looking for a similar answer for Eclipse/Zend Studio and this solved it as well.
**Note though that it must be on a single line with the opening and closing explicitly in this style...
No other formats whether...
or...
seemed to work at all. Hope that helps someone.
您是否想要记录那些讨厌的神奇变量? (我做到了;这个问题目前在 Google 中排名最高。我希望这对某人有帮助!)
@property
标签允许您记录神奇 php 变量 - 那些已实现的变量使用__get()
和__set()
。该标签应在紧接类定义之前的文档中使用:此表示法会触发自动完成,已在 Netbeans 8.1 和 PhpStorm 2016.1 中进行了测试。
Are you looking to document those pesky magic variables? (I did; This question currently ranks top result for that in Google. I hope this helps someone!)
The
@property
tag allows you to document magic php variables - those implemented using__get()
and__set()
. The tag should be used in the documentation immediately preceding the class definition:This notation triggers autocomplete, tested in Netbeans 8.1 and PhpStorm 2016.1.
根据此错误报告,语法将在NetBeans 9:
此外,值得一提的是,您可以将
[]
附加到类名以指示数组对象:不要忘记您的
use
语句,例如use Foo;
According to this bug report, the syntax will change in NetBeans 9:
Also, it's worth mentioning that you can append
[]
to a class name to indicate an array of objects:And don't forget your
use
statement, e.g.use Foo;
在 netbeans 8.0.2 中,vdoc 模板为您提供了以下信息:
但是 Netbeans 不会识别这一点,并且不会为您的对象提供正确的自动完成列表。相反,在变量声明之前使用它:
我还没有真正看到库存 vdoc 模板的巨大用途,特别是对于将用作 PDO 或 PDOStatement 对象的类变量。
我使用的一种解决方案实际上是进入
工具/选项/编辑器/代码模板(选择 PHP 作为您的语言),然后添加一个新模板。我调用了我的提示。然后在扩展文本下,使用以下模板:
In netbeans 8.0.2, the vdoc template gives you this:
Netbeans will not recognize this however, and will not give you the correct autocomplete list for your objects. Instead use this, just before your variable declaration :
I have not really seen a great use for the stock vdoc Template, especially for class variables that are going to be used as PDO or PDOStatement objects.
One solution I use is actually to go into
Tools / Options / Editor / Code Templates (with PHP selected as your Language), and add a new Template. I called mine hint . Then under Expanded Text, use the following template:
对于 NetBeans IDE 8.2 语法如下:
这至少会为静态变量正确提供类型提示。
For NetBeans IDE 8.2 syntax is like this:
This will provide the type hints properly for static variables at least.