From: graced at monroe dot wednet dot edu Operating system: XP Pro PHP version: 5.1.2 PHP Bug Type: Variables related Bug description: __autoload and require_once() variable scoping issues
Description: ------------ When __autoload requires or includes a file, any global variables in that file are in the __autoload function's scope instead of the global scope. This is consistent with the documented behavior for include() ("When a file is included, the code it contains inherits the variable scope of the line on which the include occurs."), but is not very useful for the __autoload case -- if the class being instantiated require()s another file (say, a function library) and the required file depends on certain global variables that it also defines, it will fail messily as the functions that depend on those variables won't see them, as they are in __autoload()'s scope instead of the global scope. Reproduce code: --------------- main.php: <?php function __autoload($class) { require_once('class.php'); } $foo = new myclass(); class.php: <?php require_once('required.php'); class myclass { }; required.php: <?php $var = 'some value'; function test() { if(isset($GLOBALS['var'])) { echo 'var is in the global scope'; } else { echo 'var is not in the global scope'; } } test(); Expected result: ---------------- "var is the global scope" should be echoed. Actual result: -------------- "var is not in the global scope" is echoed. -- Edit bug report at http://bugs.php.net/?id=36594&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=36594&r=trysnapshot44 Try a CVS snapshot (PHP 5.1): http://bugs.php.net/fix.php?id=36594&r=trysnapshot51 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=36594&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=36594&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=36594&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=36594&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=36594&r=needscript Try newer version: http://bugs.php.net/fix.php?id=36594&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=36594&r=support Expected behavior: http://bugs.php.net/fix.php?id=36594&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=36594&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=36594&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=36594&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=36594&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=36594&r=dst IIS Stability: http://bugs.php.net/fix.php?id=36594&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=36594&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=36594&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=36594&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=36594&r=mysqlcfg