hen*_*ght 5 php closures phpdoc
将匿名函数作为参数传递时,应如何记录它?例如:
// Call my_function(), passing 2 arguments.
my_function( 'foo', function() {
// Body of the anon function I'd like to document.
} );
Run Code Online (Sandbox Code Playgroud)
提前致谢。
为了记录函数接受闭包,我建议callable:
/**
* Do something.
* @param callable $code
*/
function foo(callable $code) {
}
Run Code Online (Sandbox Code Playgroud)
关于注释,PHPDoc 使用 DocBlocks,PHP 引擎 Tokenizer 只识别上述正式定义。因此,PHPDoc 将看不到以下内容:
/**
* My closure. PHPDoc will *not* parse this, because it's not a formal definition.
* @param string $name
*/
$closure = function ($name) { return $name; };
Run Code Online (Sandbox Code Playgroud)