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!
I admit that I"m rather new at this ... but not to programming ... and this is confusing me...
in the following the fist echo statment yeilds "chaos" --- this is good ... the second yeilds "=" or a char similar --- this is confusing as it's global ... or am I missing something? ( code snipped )
global is a scope of it's own and functions cannot access it by default (since all their variables are created in the function's scope)
To have access to a global scope var from within a function you have to mark it as global, e.g.
$db_name = 'Chaos';
function test()
{
global $db_name;
echo $db_name; // without global the lookup for $db_name would be in test's scope
$db_name = ' something else';
}
test();
echo $db_name;