Netbeans(PHP)中的变量类型提示 [英] Variable type hinting in Netbeans (PHP)
问题描述
好奇的是,netbeans中是否有一种方法可以为常规变量提供类型提示,以便intellisense可以选择.我知道您可以针对类属性,函数参数,返回类型等执行此操作,但是我不知道如何针对常规变量执行此操作.在您拥有可以返回不同对象类型(例如服务定位符)的方法的情况下,这确实有帮助.
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).
例如:
/**
* @var Some_Service $someService
*/
$someService = ServiceLocator::locate('someService');
随后在使用$ someService的地方,netbeans将提供在Some_Service类中定义的所有可用方法.
Where using $someService afterward, netbeans would provide all available methods defined in the class Some_Service.
推荐答案
仅需一行:
/* @var $varName Type_Name */
在NetBeans PHP博客中查看此文章: https://blogs.oracle.com/netbeansphp/entry/defining_a_variable_type_in
See this article in the NetBeans PHP Blog: https://blogs.oracle.com/netbeansphp/entry/defining_a_variable_type_in
注意:至少在8.2版中;关键似乎是:
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).
这篇关于Netbeans(PHP)中的变量类型提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!