From:             adam dot jimenez at gmail dot com
Operating system: any
PHP version:      5.3.0
PHP Bug Type:     Variables related
Bug description:  global variable not fully global when declared in a function 
within a function

Description:
------------
In the example function test2 is declared in function test.
Function test2 declares the variable $test as global.
$test is available inside test2 and outside the function but crucially not
in function test.

this may seem strange practice to declare a function within a function.
but it can be useful in a function or class-based template system which is
including other files and projects like wordpress.
see: http://wordpress.org/support/topic/288455

Reproduce code:
---------------
<?php
function test()
{
        function test2()
        {
                global $test;
                $test='nads'."\n";
        }
        
        test2();        
        print $test; //doesn't work
}

test();
print $test; //works
?>

Expected result:
----------------
nads
nads

Actual result:
--------------
nads

-- 
Edit bug report at http://bugs.php.net/?id=50042&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=50042&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=50042&r=trysnapshot53
Try a snapshot (PHP 6.0):            
http://bugs.php.net/fix.php?id=50042&r=trysnapshot60
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=50042&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=50042&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=50042&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=50042&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=50042&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=50042&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=50042&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=50042&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=50042&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=50042&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=50042&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=50042&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=50042&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=50042&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=50042&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=50042&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=50042&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=50042&r=mysqlcfg

Reply via email to