note 95778 added to functions.anonymous
| From: | kwilson at shuttlebox dot net | Date: | Thu, 21 Jan 2010 15:24:38 +0000 |
| Subject: | note 95778 added to functions.anonymous | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-165166@lists.php.net to get a copy of this message | ||
Using the global keyword apparently pulls variables from the scope where the function was created,
not where it is executed.
Example:
<?php
$variable = "first";
$closure = function() {
global $variable;
echo $variable . "\n";
};
$closure();
function test($closure)
{
$variable = "second";
$closure();
}
test($closure);
?>
Will print:
first
first
----
Server IP: 69.147.83.197
Probable Submitter: 74.204.0.4
----
Manual Page -- http://www.php.net/manual/en/functions.anonymous.php
Edit -- https://master.php.net/note/edit/95778
Del: integrated -- https://master.php.net/note/delete/95778/integrated
Del: useless -- https://master.php.net/note/delete/95778/useless
Del: bad code -- https://master.php.net/note/delete/95778/bad+code
Del: spam -- https://master.php.net/note/delete/95778/spam
Del: non-english -- https://master.php.net/note/delete/95778/non-english
Del: in docs -- https://master.php.net/note/delete/95778/in+docs
Del: other reasons-- https://master.php.net/note/delete/95778
Reject -- https://master.php.net/note/reject/95778
Search -- https://master.php.net/manage/user-notes.php