php - Netbeans (PHP) 中的变量类型提示

标签 php phpdoc php-ide

只是好奇 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/

相关文章:

php - 我如何在 PHP 中找到所有加起来等于给定总和的 N 个单位数、非重复数字集?

PHP Doc 泛型类型声明

php - 记录文件、类和构造函数的正确方法是什么?

php - PHP Web开发IDE

PHPDoc 和后期(静态或动态)绑定(bind)

php - 给 PHP 对象类型参数一个默认值

php - 来自 Symfony 命令的 Swift 邮件

php - Netbeans 风格的回顾性自动注释/phpDocumentor 工具(用于 Eclipse 或独立)

php - 到达最后一行时如何回显不同的内容?