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
