global variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

global variables

Post by kendall »

Hello,

i have in an included file of a main file, a function that has

if($info){
global $info;
return true;
}

in the main file have a echo $info;

Now i know the info has data as test have proven so. But for some reason its not echoing $info how does the global $info affected in included files?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

your switching to the global scope too late

Code: Select all

<?php
function test()
{
	$i = 0; // setting test::$i
	global $i; // setting the scope of $i to global
	// the local test::$i is lost
}
?>
Post Reply