|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-03-02 22:12 UTC] johannes@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 01:00:01 2025 UTC |
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.