【发布时间】:2013-05-11 11:48:28
【问题描述】:
我在 PHPDoc 中找不到任何关于 Closure 类型的文档。所以我的问题是如何定义发送给闭包的参数的参数及其返回值?
例子:
我如何描述“回调”将获得一个“MyCustomClass”、一个数字和一个字符串,并返回一个“MyOtherCustomClass”?
/**
* @param MyCustomClass $cls
* @param Closure $callback this isn't really explaining what this is
*
* @return MyOtherCustomClass
*/
function changer($cls, $callback){
return $callback($cls, 2, "a string");
}
changer($aCustomeClass, function($cls, $int, $string){
return new MyOtherCustomClass($cls, $int, $string);
})
或者如果可能的话?
【问题讨论】:
-
我认为没有合理的方式在注释中描述它。即使在 PHP 手册中,它们也只是在参数描述中引用为
callable。 -
这就是我所担心的,但如果可能的话,那就太好了。