PHP Documentor 中的注释关联数组
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2713710/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Comment associative array in PHP Documentor
提问by Abenil
I use several associative arrays in my PHP application and I'm using PHP documentor to comment my sources. I never really did specify comments for the arrays in an array, but now I need to do that and don't know how.
我在我的 PHP 应用程序中使用了几个关联数组,并且我正在使用 PHP 文档器来注释我的源代码。我从来没有真正为数组中的数组指定注释,但现在我需要这样做,但不知道如何做。
$array = array('id' => 'test', 'class' => 'tester', 'options' => array('option1' => 1, 'option2' => 2))
How do I comment this array in the correct way for @varand @paramcomments?
I could do this like this, but I don't know if this is correct:
我如何评论这个数组中的正确方法@var和@param意见吗?我可以这样做,但我不知道这是否正确:
@param string $array['id']
@param string $array['class']
@param int $array['options']['option1']
But how to do this for the @varpart?
但是如何为@var零件做到这一点?
回答by Stephen Fuhry
You can't document each key, but you can tell phpDocumentor what type it is.
你不能记录每个键,但你可以告诉 phpDocumentor 它是什么类型。
You could do something like this:
你可以这样做:
/**
* Form the array like this:
* <code>
* $array = array(
* 'id' => 'foo', // the id
* 'class' => 'myClass', // the class
* );
*
* </code>
*
* @var array[string]string
*/
$array;
回答by Tom Auger
I would look at the WordPress Inline Documentation Referencefor some hints, though it's not currently comprehensive.
我会查看WordPress 内联文档参考以获得一些提示,尽管它目前并不全面。
Use @param or @var or @property, whichever is appropriate in your context
使用 @param 或 @var 或 @property,以适合您的上下文为准
According to those guidelines, you might document your associative array like this:
根据这些指南,您可以像这样记录关联数组:
/**
* @property array $my_array {
* An array of parameters that customize the way the parser works.
*
* @type boolean $ignore_whitespace Whether to gobble up whitespace. Default true.
* @type string $error_level What the error reporting level is. Default 'none'.
* Accepts 'none', 'low', 'high'.
* }
*/
回答by Richárd Vastag
For me this works fine in PhpStorm for nice return value description:
对我来说,这在 PhpStorm 中很好用,以获得很好的返回值描述:
/**
* @param string $requestUri
* @return array[
* 'controller' => string,
* 'action' => string
* ]
*/

