Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable scope issue

Status
Not open for further replies.

TheDust

Programmer
Aug 12, 2002
217
US
I have a file with two includes:

Code:
// include global variables
include("includes/globals.inc.php");
// include site functions
include("includes/functions.inc.php");

For some reason, functions.inc.php cannot read variables from globals.inc.php. The page that these files are being included on can read the variables just fine. However, when I call a function from functions.inc.php I get:

Notice: Undefined variable: global_SiteNavigation in /xxx_site_root/includes/functions.inc.php</b> on line 34

Then the function looks to use the values in that array, but can't find it. Any idea why this is?
 
Insufficient data for a meaninful answer.

What do the two scripts do?


In general, variables instantiated outside of a function are not available within that function -- the exceptions being the superglobal variables, such as $_POST, $_GET, etc.

That said, you can make an externally-instantiated variable available inside a function using the "global" operator.

See
Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Using the global operator worked. Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top