Search code examples
phpclosuresdoxygendereferencephpdocumentor2

Documentation of dereferenced closure in PHP


How should I document the final_nums constant using doxygen or phpdocumentor markup? The closure was not documentable in older phpdocumentor but as of phpdocumentor2 they should have full php 5.3 support. To complicate documentation just a little more, the closure is short lived by the dereferencing.

I believe the resultant documentation should explain that the constant is composed of the results of an anonymous function that takes arguements of (int)prefix and (string)input and returns a (int)result.

$prefix = 1234;
$input = $_GET['input'];
define( 'final_nums', call_user_func(function() use ( $prefix, $input ) {       
    $no_str = preg_replace( '/[^0-9]/', '', $input );
    $output = $prefix . $no_str;
    return $output;
}));

Solution

  • /** * A constant that is generated based on $prefix and $input at runtime * @var int * @see $prefix * @see $input */ define( ... ); The closure used for implementation seems inconsequential to me, the reader, if my concern is what the constant is.

    If/when the @type tag is implemented, it will be the better choice over @var for denoting the datatype.