PHP 5.2 Added the function of anonymous function, but I found the problem when the anonymous function recursion
0) { return $test ($a); }}; $test (10);
As shown in the code above, I want to $test invoke it myself recursively in this anonymous function, but I find that it appears after the call.
Fatal error:function Name must be a string in/library/webserver/documents/test.php on line 9
That is $test , this variable is not recognized, can we have a way to recursively function in the anonymous function itself?
Reply content:
PHP 5.2 Added the function of anonymous function, but I found the problem when the anonymous function recursion
0) { return $test ($a); }}; $test (10);
As shown in the code above, I want to $test invoke it myself recursively in this anonymous function, but I find that it appears after the call.
Fatal error:function Name must be a string in/library/webserver/documents/test.php on line 9
That is $test , this variable is not recognized, can we have a way to recursively function in the anonymous function itself?
Need to pass $test as a reference with order for it
$test = function ($a) use (& $test) { ...}
Reference:http://stackoverflow.com/questions/24 ...
Tips:google helps.
php5.4 down through
$test = NULL, $test = function ($a) use (& $test) { echo $a; $a--; if ($a > 0) { return $test ($a); }}; $test (10);