Edit report at http://bugs.php.net/bug.php?id=49717&edit=1

 ID:                 49717
 Updated by:         [email protected]
 Reported by:        oliver dot saunders at gmail dot com
 Summary:            Unable to recurse within an anonymous function
-Status:             Open
+Status:             Bogus
 Type:               Feature/Change Request
-Package:            Feature/Change Request
+Package:            Scripting Engine problem
 Operating System:   Mac OS X
 PHP Version:        5.3.0
 Block user comment: N
 Private report:     N

 New Comment:

See last comment.


Previous Comments:
------------------------------------------------------------------------
[2010-05-28 21:37:14] dchurch at sciencelogic dot com

This is the syntax you're looking for:



$c = function($n) use(&$c) { 

  if ($n > 0) { 

    echo $n . PHP_EOL; 

    $c($n - 1); } };



$c(4);

------------------------------------------------------------------------
[2009-09-29 22:08:10] oliver dot saunders at gmail dot com

You can workaround like this:



$c = function($self, $n) { 

  if ($n > 0) { 

    echo $n . PHP_EOL; 

    $self($self, $n - 1); } };

$c($c, 4);



...but that's not really the point.

------------------------------------------------------------------------
[2009-09-29 22:06:26] oliver dot saunders at gmail dot com

Description:
------------
Unable to recurse within an anonymous function.

Reproduce code:
---------------
$c = function($n) use($c) { 

  if ($n > 0) { 

    echo $n . PHP_EOL; 

    $c($n - 1); } };



$c(4);

Expected result:
----------------
4

3

2

1



Actual result:
--------------
4



Fatal error: Function name must be a string in Command line code on line


4


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=49717&edit=1

Reply via email to