|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-01-21 15:28 UTC] johannes@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Dec 04 12:00:02 2025 UTC |
Description: ------------ If an anonymous function pulls a variable from the global scope using "global", and that function is passed to another scope, it pulls the variable from the scope where the function was created, not where it was executed. Reproduce code: --------------- <?php $variable = "first"; $closure = function() { global $variable; echo $variable . "\n"; }; $closure(); function test($closure) { $variable = "second"; $closure(); } test($closure); ?> Expected result: ---------------- first second Actual result: -------------- first first