Re: Globals unavailable, require oddity

From: Date: Fri, 14 Oct 2005 06:07:17 +0000
Subject: Re: Globals unavailable, require oddity
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-19611@lists.php.net to get a copy of this message
If you include a file within a function, that file will be loaded in that function's scope. Example: <?php function test() { include 'a.inc.php'; } test(); echo isset($a) ? '$a is set' : '$a is not set', ".\n"; include 'a.inc.php'; echo isset($a) ? '$a is set' : '$a is not set', ".\n"; ?> The same happens if b.class.php is included within a function (or class member, etc.) and includes a.inc.php, as in your example (I am presuming.) If this is the problem, I suggest simply adding: global $a; At the top of a.inc.php, which will solve the problem for you. -[Unknown]

« previous php.internals (#19611) next »