How should I document an anonymous function when it's passed as an argument? For example:
// Call my_function(), passing 2 arguments.
my_function( 'foo', function() {
// Body of the anon function I'd like to document.
} );
Thanks in advance.
To document that a function accepts a Closure, I'd suggest callable:
/**
* Do something.
* @param callable $code
*/
function foo(callable $code) {
}
Regarding the commentary, PHPDoc uses DocBlocks, which the PHP engine Tokenizer only recognizes above formal definitions. Thus, PHPDoc will not see this:
/**
* My closure. PHPDoc will *not* parse this, because it's not a formal definition.
* @param string $name
*/
$closure = function ($name) { return $name; };
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With