问题描述
我使用Zend Studio通过CakePHP在PHP中进行开发,而CakePHP的问题之一是视图都引用了未声明的局部变量.
I use Zend Studio to develop in PHP with CakePHP, and one of the problems with CakePHP is that the views all reference undeclared local variables.
例如,您将在控制器中
$ this-> set('job',new MyJobObject());
然后在视图中可以
echo $ job-> getName();
我的问题是Zend Studio无法在 $ job
上执行自动完成,因为它的类型未知.现在有PHPDoc标记,允许您声明类型,以便IDE可以执行自动完成.例如, @var
标记可在类中用于定义属性的类型.
My problem is that Zend Studio can't perform autocomplete on $job
, because it's type is unknown. Now there are PHPDoc tags that allow you to declare the type so that IDE's can perform autocomplete. The @var
tag for example can be used in a class to define a property's type.
class MyJobObject
{
/**
* @var MyStatusObject
*/
public $status;
}
是否可以对本地变量执行类似的操作?
推荐答案
您必须使用单行形式:/** @var $ job MyJobObject */
You have to use the one-line form: /** @var $job MyJobObject */
请注意,某些编辑器更喜欢语法:/** @var MyJobObject $ job */
Note that some editors prefer the syntax the other way around: /** @var MyJobObject $job */
这篇关于如何使用PHPDoc表示法声明局部变量的类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!