note 65964 added to function.create-function
| From: | info at adaniels dot nl | Date: | Wed, 10 May 2006 22:42:34 +0000 |
| Subject: | note 65964 added to function.create-function | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-111096@lists.php.net to get a copy of this message | ||
Note that using __FUNCTION__ in a an anonymous function, will always result
'__lambda_func'.
<?php
$fn = create_function('', 'echo __FUNCTION__;');
$fn();
// Result: __lambda_func
echo $fn;
// Result: ºlambda_2 (the actual first character cannot be displayed)
?>
This means that a anonymous function can't be used recursively. The following code (recursively
counting to 10) results in an error:
<?php
$fn2 = create_function('$a', 'echo $a; if ($a < 10) call_user_func(__FUNCTION__,
$a++);');
$fn2(1);
// Warning: call_user_func(__lambda_func) [function.call-user-func]: First argument is expected to
be a valid callback in T:/test/test.php(21) : runtime-created function on line 1
?>
----
Server IP: 83.137.20.120
Probable Submitter: 213.84.27.165
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.create-function.php
Edit -- http://master.php.net/note/edit/65964
Del: integrated -- http://master.php.net/note/delete/65964/integrated
Del: useless -- http://master.php.net/note/delete/65964/useless
Del: bad code -- http://master.php.net/note/delete/65964/bad+code
Del: spam -- http://master.php.net/note/delete/65964/spam
Del: non-english -- http://master.php.net/note/delete/65964/non-english
Del: in docs -- http://master.php.net/note/delete/65964/in+docs
Del: other reasons-- http://master.php.net/note/delete/65964
Reject -- http://master.php.net/note/reject/65964
Search -- http://master.php.net/manage/user-notes.php