Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP Documentor中的注释关联数组_Php_Arrays_Associative Array_Phpdoc - Fatal编程技术网

PHP Documentor中的注释关联数组

PHP Documentor中的注释关联数组,php,arrays,associative-array,phpdoc,Php,Arrays,Associative Array,Phpdoc,我在PHP应用程序中使用了几个关联数组,并使用PHP documentor对我的源代码进行注释。我从来没有为数组中的数组指定注释,但现在我需要这样做,不知道怎么做 $array = array('id' => 'test', 'class' => 'tester', 'options' => array('option1' => 1, 'option2' => 2)) 对于@var和@param注释,如何以正确的方式对该数组进行注释? 我可以这样做,但我不知道这是

我在PHP应用程序中使用了几个关联数组,并使用PHP documentor对我的源代码进行注释。我从来没有为数组中的数组指定注释,但现在我需要这样做,不知道怎么做

$array = array('id' => 'test', 'class' => 'tester', 'options' => array('option1' => 1, 'option2' => 2))
对于
@var
@param
注释,如何以正确的方式对该数组进行注释? 我可以这样做,但我不知道这是否正确:

@param string $array['id']
@param string $array['class']
@param int $array['options']['option1']

但是如何对
@var
部分执行此操作?

您不能记录每个键,但是

你可以这样做:

/**
 * Form the array like this:
 * <code>
 * $array = array(
 *   'id'      => 'foo',          // the id
 *   'class'   => 'myClass',     // the class
 * );
 * 
 * </code>
 *
 * @var array[string]string 
 */
$array;
/**
 * @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'.
 * }
 */
我会查看一些提示,尽管目前还不全面

使用@param或@var或@property,以上下文中合适的为准

根据这些指导原则,您可以这样记录关联数组:

/**
 * Form the array like this:
 * <code>
 * $array = array(
 *   'id'      => 'foo',          // the id
 *   'class'   => 'myClass',     // the class
 * );
 * 
 * </code>
 *
 * @var array[string]string 
 */
$array;
/**
 * @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'.
 * }
 */

对于我来说,这在PhpStorm中可以很好地进行返回值描述:

/**
 * @param string $requestUri
 * @return array[
 *  'controller' => string,
 *  'action' => string
 * ]
 */

我想知道,在任何IDE中,这是否已被证实可以与自动完成/智能感知一起工作?根据,不允许为数组索引指定类型。它将数组指定为
@var string[]
array
组件只应该出现在“未指定”的数组中)。@Sepster不幸的是,我认为大多数IDE都不够聪明,无法识别这一点。您的里程数可能会有所不同,但我甚至发现Zend Studio的实现在这种accute类型感知方面有点欠缺。Sepster评论中提到的ABNF更新链接:该示例令人困惑,通过查看
@var
注释无法确定数组键或值使用哪种类型。现在,我无法确定方括号内或方括号后的
字符串
类型提示是否指定了键的类型。最新的类型ABNF:这种用于记录数组结构的符号从未写入官方PHPDoc规范,尽管在2013-14年对添加它进行了认真讨论。似乎在WordPress指南似乎与《诗篇》所推荐的内容类似:在Webstorm 2020.1 EAP中尝试了这个参数描述,但它破坏了帮助弹出窗口。以我的经验,这是行不通的。