note 113896 added to functions.anonymous
| From: | cHao | Date: | Fri, 13 Dec 2013 23:42:28 +0000 |
| Subject: | note 113896 added to functions.anonymous | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-197932@lists.php.net to get a copy of this message | ||
In case you were wondering (cause i was), anonymous functions can return references just like named
functions can. Simply use the & the same way you would for a named function...right after the
function keyword (and right before the nonexistent name).
<?php
$value = 0;
$fn = function &() use (&$value) { return $value; };
$x =& $fn();
var_dump($x, $value); // 'int(0)', 'int(0)'
++$x;
var_dump($x, $value); // 'int(1)', 'int(1)'
----
Server IP: 72.52.91.14
Probable Submitter: 72.52.91.14
----
Manual Page -- http://php.net/manual/en/functions.anonymous.php
Edit -- https://master.php.net/note/edit/113896
Del: integrated -- https://master.php.net/note/delete/113896/integrated
Del: useless -- https://master.php.net/note/delete/113896/useless
Del: bad code -- https://master.php.net/note/delete/113896/bad+code
Del: spam -- https://master.php.net/note/delete/113896/spam
Del: non-english -- https://master.php.net/note/delete/113896/non-english
Del: in docs -- https://master.php.net/note/delete/113896/in+docs
Del: other reasons-- https://master.php.net/note/delete/113896
Reject -- https://master.php.net/note/reject/113896
Search -- https://master.php.net/manage/user-notes.php