Global unavailable?

From: Date: Wed, 05 Oct 2005 10:37:04 +0000
Subject: Global unavailable?
Groups: php.general 
Request: Send a blank email to php-general+get-223645@lists.php.net to get a copy of this message
I have a simple situation: in a.inc.php: $a = 1; in b.class.php require 'a.inc.php'; class b {
    function test() {
        global $a;
        echo $a;
    }
} With this pattern, $a is NOT visible within class b, even though it is declared in the global scope and I'm using the global keyword! I can work around it two ways; by changing the original declaration (which just seems wrong - it's already in the global scope at this point): global $a; $a = 1; or by requiring the inc file inside each function of b (much less efficient): class b {
    function test() {
        require 'a.inc.php';
        global $a;
        echo $a;
    }
} Is this just how it is, or am I doing something wrong? Marcus -- Marcus Bointon Synchromedia Limited: Putting you in the picture marcus@synchromedia.co.uk | http://www.synchromedia.co.uk

« previous php.general (#223645) next »