只是好奇 netbeans 中是否有一种方法可以为常规变量提供类型提示,以便智能感知将其拾取。我知道您可以对类属性、函数参数、返回类型等执行此操作,但我不知道如何对常规变量执行此操作。在您拥有可以返回不同对象类型的方法(例如服务定位器)的情况下,这将非常有用。
例如:
/**
* @var Some_Service $someService
*/
$someService = ServiceLocator::locate('someService');
在之后使用 $someService 时,netbeans 将提供 Some_Service 类中定义的所有可用方法。
最佳答案
你只需要一行:
/* @var $varName Type_Name */
请参阅 NetBeans PHP 博客中的这篇文章:https://blogs.oracle.com/netbeansphp/entry/defining_a_variable_type_in
Note: At least, in version 8.2; The key seems to be:
- The single asterisk (
/*
instead of/**
).- Placing the type after the variable name.
- Having nothing before and after the type-hinting (except white-space, but even that is not allowed when the comment is not in a single line).
关于php - Netbeans (PHP) 中的变量类型提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1798477/