在PHP中注释局部变量 [英] annotating a local variable in php

查看:74
本文介绍了在PHP中注释局部变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Eclipse PDT,并且想使用Phpdoc注释局部变量.

I am using Eclipse PDT and I want to annotate a local variable using Phpdoc.

我所看到的就是我可以使用 @var 甚至甚至是注释类的变量/属性. @property ,但是对于局部变量怎么可能呢?

All I see is that I can annotate the variables/properties of a class using @var or even @property, but how is this possible for a local variable?

我该怎么做?

function foo(){
  /** @var Stock $a */
  $a->save();
}

推荐答案

Phpdoc标准不涵盖这些注释(仅涵盖具有 @var 标记的类属性);但是,在Eclipse(例如PDT)中完全有可能:

The Phpdoc standard does not cover these annotations (it only cover class properties with the @var tag); however, it is perfectly possible in Eclipse (e.g. PDT):

/* @var $variable Type */
 ^         ^        `--- type
 |      variable           
 |
 `--- single star

这也可以在所有其他PHP IDE(例如Netbeans或Phpstorm)中使用,如果您与他人交换代码,这将很有用.

This also works in all other PHP IDEs like Netbeans or Phpstorm which is useful if you exchange your code with others.

示例代码:

<?php

/* @var $doc DOMDocument */
$doc->
 

示例屏幕截图(Eclipse PDT(Indigo)):

Example Screenshot (Eclipse PDT (Indigo)):

相关问题与解答答案:

这篇关于在PHP中注释局部变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆