note 91885 added to functions.anonymous
| From: | nate at example dot com | Date: | Tue, 30 Jun 2009 18:28:14 +0000 |
| Subject: | note 91885 added to functions.anonymous | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-157713@lists.php.net to get a copy of this message | ||
Am I the only one who finds it ridiculous that you have to explicitly import variables into a
closure (using the "use" syntax)? A closure by definition should inherit the scope of the
parent where the closure is defined
If php played by the rules of standard programming practice, the following example would work as-is,
without having to add a "use ($var)" clause. Flawed implementation, like so many things in
the world of php.
<?
$var = 'hello';
$lamba = function () { var_dump($var); };
$lambda();
?>
----
Server IP: 66.207.199.35
Probable Submitter: 69.70.125.250
----
Manual Page -- http://www.php.net/manual/en/functions.anonymous.php
Edit -- https://master.php.net/note/edit/91885
Del: integrated -- https://master.php.net/note/delete/91885/integrated
Del: useless -- https://master.php.net/note/delete/91885/useless
Del: bad code -- https://master.php.net/note/delete/91885/bad+code
Del: spam -- https://master.php.net/note/delete/91885/spam
Del: non-english -- https://master.php.net/note/delete/91885/non-english
Del: in docs -- https://master.php.net/note/delete/91885/in+docs
Del: other reasons-- https://master.php.net/note/delete/91885
Reject -- https://master.php.net/note/reject/91885
Search -- https://master.php.net/manage/user-notes.php