ID:               50042
 User updated by:  adam dot jimenez at gmail dot com
 Reported By:      adam dot jimenez at gmail dot com
 Status:           Bogus
 Bug Type:         Variables related
 Operating System: any
 PHP Version:      5.3.0
 New Comment:

after thinking about is some more this does makes sense.

Altho I think it means that what I'm trying to achieve is impossible 
with php.


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

[2009-10-30 19:25:29] adam dot jimenez at gmail dot com

//Global doesn't make a variable global but imports a variable fro
mthe
global scope (outside of all functions) into the current
function/method.

so how come it's added to the $GLOBALS array and can be accessed from 
outside the function?

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

[2009-10-30 15:30:39] [email protected]

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 doesn't make a variable global but imports a variable fro mthe
global scope (outside of all functions) into the current
function/method.

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

[2009-10-30 15:03:46] adam dot jimenez at gmail dot com

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 this bug report at http://bugs.php.net/?id=50042&edit=1

Reply via email to