Global unavailable?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxxxx | http://www.synchromedia.co.uk

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux