ID:               50814
 Updated by:       [email protected]
 Reported By:      kwilson at shuttlebox dot net
-Status:           Open
+Status:           Bogus
 Bug Type:         Unknown/Other Function
 Operating System: Linux
 PHP Version:      5.3.1
 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

global imports from the global scope, not the caller's or such.


Previous Comments:
------------------------------------------------------------------------

[2010-01-21 15:14:35] kwilson at shuttlebox dot net

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


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=50814&edit=1

Reply via email to