Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.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
我应该如何进行PHPDoc回调?_Php_Phpdoc - Fatal编程技术网

我应该如何进行PHPDoc回调?

我应该如何进行PHPDoc回调?,php,phpdoc,Php,Phpdoc,我有一个方法,可以从数据库中提取一个修改过的前序树横截树,并使用回调函数对其进行过滤。例如: /** * Recursive function for building the Cas_Template_TreeNode. * * @static * @param array $rows * @param callback $filter A function to filter the tree by (return a value convertible to false to r

我有一个方法,可以从数据库中提取一个修改过的前序树横截树,并使用回调函数对其进行过滤。例如:

/**
 * Recursive function for building the Cas_Template_TreeNode.
 *
 * @static
 * @param array $rows
 * @param callback $filter A function to filter the tree by (return a value convertible to false to remove the item from the tree)
 * @return array
 */
private static function MakeTreeGivenDbRows($rows, $filter = null)
{
    if ($filter === null)
    {
        $filter = function($unused)
        {
            return true;
        };
    }
    $result = array();
    $childrenCount = 0;
    for ($idx = 0; $idx < count($rows); $idx += $childrenCount + 1)
    {
        $current = $rows[$idx];
        $childrenCount = self::ChildrenCountFromRow($current);
        if (!$filter($current))
        {
            continue;
        }
        $childrenStartAt = $idx + 1;
        $childRows = array_slice($rows, $childrenStartAt, $childrenCount);
        $children = self::MakeTreeGivenDbRows($childRows, $filter);
        $result[] = new Cas_Template_TreeNode(self::MakeNodeGivenDbRow($current), $children);
    }
    if (empty($result))
    {
        return null;
    }
    return $result;
}
/**
*用于构建Cas_模板_树节点的递归函数。
*
*@静态
*@param数组$rows
*@param callback$filter用于筛选树的函数(返回可转换为false的值以从树中删除项目)
*@return数组
*/
私有静态函数MakeTreeGivenDbRows($rows,$filter=null)
{
如果($filter==null)
{
$filter=函数($unused)
{
返回true;
};
}
$result=array();
$childrenCount=0;
对于($idx=0;$idx
我不确定变量
$filter
的PHPDoc应该是什么——这是一个回调,我已经指出了这一点,但我不确定这是否正确


另外,对于这段代码中的质量(或缺乏质量)的任何其他评论都将不胜感激:)

关于
@param
标记的文档似乎没有在很久以前更新过,因此它没有提到任何关于使用
create_function()进行的闭包或回调的内容


如果phpDocumentor拒绝将
callback
识别为数据类型,则必须使用
mixed

phpDoc没有真正指定接受的变量类型是什么,只是它们应该是有效的php变量类型的名称。在这种情况下,“回调”是正确的。这是PHP中伪类型的名称。

“回调”在phpDocumentor中作为有效的数据类型工作。。。我刚核实过。。。至少使用PHP5.2.4。“有效数据类型”取决于运行phpDocumentor的PHP版本是可行的。

正确的类型提示是
可调用的
,它在例如PhpStorm中已经存在很长时间,并且是当前规范中的一部分

(我很惊讶没有人提到
callable
,这并不是什么新鲜事,而且已经在任何地方使用多年了——据我所知,
callback
不是也从来不是一个定义好的PHP)


请注意,
callable
不仅包括闭包,还包括“老派”PHP回调,例如
array($object,'methodName')
array('ClassName','methodName')
,甚至
'function_name'
——为了最大限度地发挥API的效用,您应该涵盖所有这些用例,这非常简单,因为和都支持所有四种类型的可调用项:函数名为字符串、对象/方法名、类/方法名和闭包。

我不确定它是否将
回调
识别为数据类型。@Billy ONeal:我想你必须通过phpDocumentor运行PHP文件并找出答案。或者,如果您只是非正式地执行此操作,而不需要生成文档页面,那么只调用
回调
不会有什么坏处。在编写所有这些答案时,
回调
是正确的答案。引用您链接到的PHP伪类型文章:“在PHP 5.4引入可调用类型提示之前,本文档中使用了回调伪类型。它的意思完全相同。”所有其他答案和问题都早于PHP 5.4,因此它们在当时是正确的。这个答案在编写时是正确的。然而,从PHP5.4开始,它不再是正确的答案。