Posted by Marcus Bointon on 10/21/24 11:28
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
[Back to original message]
|