如何在 PHP (Java)Doc 中标记数组值类型?
解释起来可能有点困难,所以我将给出一些示例代码。请注意,我使用的是 NetBeans IDE(最新)。
class Dummy {
public function say(){ }
}
/**
* Builds dummy class and returns it.
* @return Dummy The dummy class.
*/
function say_something(){
return new Dummy();
}
$s=say_something();
在使用 netbeans 进行开发时,我可以在输入“$s->”后按 ctrl+space 来调用自动完成功能。 在随后的提示窗口中,有“say()”项。这是因为 javadoc 说 say_something 返回一个 Dummy,而 NetBeans 解析 Dummy 类知道它有一个名为“say()”的方法。
到目前为止,一切都很好。
我的问题是数组。示例代码如下:
/**
* Builds array of 2 dummy classes and returns it.
* @return Array The dummy class. (*)
*/
function say_something2(){
return array(new Dummy(),new Dummy());
}
$s=say_something2();
如果我再次尝试自动完成,但使用“$s[0]->”相反,我没有获得虚拟类的方法。这是因为在 JavaDoc 中我只说它是一个数组,但没有说值的类型。
所以问题是,是否有任何 JavaDoc 语法、欺骗或任何允许我告诉 JavaDoc 数组中期望什么类型的变量的东西?
It might be a bit difficult to explain, so I'll give some example code. Note that I'm using NetBeans IDE (latest).
class Dummy {
public function say(){ }
}
/**
* Builds dummy class and returns it.
* @return Dummy The dummy class.
*/
function say_something(){
return new Dummy();
}
$s=say_something();
While developing in netbeans I can invoke auto-complete by hitting ctrl+space after typing "$s->".
In the the hint window that follows, there is the item "say()". This is because the javadoc says say_something returns a Dummy and NetBeans parsed Dummy class to know that it has a method called "say()".
So far so good.
My problem is with arrays. Example code follows:
/**
* Builds array of 2 dummy classes and returns it.
* @return Array The dummy class. (*)
*/
function say_something2(){
return array(new Dummy(),new Dummy());
}
$s=say_something2();
If I try the auto-complete thing again but with "$s[0]->" instead, I don't get the methods fro Dummy class. This is because in the JavaDoc I only said that it is an array, but not the values' type.
So the question would be, is there any JavaDoc syntax, cheat, whatever which allows me to tell JavaDoc what type of variables to expect in an array?
你不能。请参阅此处的文档。
You can't. See the documentation here.