ID:               36594
 Updated by:       [EMAIL PROTECTED]
 Reported By:      graced at monroe dot wednet dot edu
-Status:           Open
+Status:           Bogus
 Bug Type:         Variables related
 Operating System: XP Pro
 PHP Version:      5.1.2
 New Comment:

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

Changing this would be a major BC break so this won't be 
changed.


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

[2006-03-02 20:14:14] graced at monroe dot wednet dot edu

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

Reply via email to