'Global' variable scope.
| From: | John Parker | Date: | Fri, 29 Jun 2001 11:01:29 +0000 |
| Subject: | 'Global' variable scope. | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-58447@lists.php.net to get a copy of this message | ||
Hi, all.
I'm just wondering why a variable defined within a function is not available
as a global to functions called from the same scope. There's probably a
really good reason for this, but I'm not sure I know what it is.
Feel free to educate me.
Ta muchly,
JP.
--- Code example follows ---
<?PHP
// Simple global variable scope test.
Function startTests()
{
$G_test =
"Hello, World.";
globalTest();
}
Function globalTest()
{
global $G_test;
if
(isset($G_test))
{
echo ("Global variable 'test' - value:
'<B>".$G_test."</B>'.<P>\n");
}
else echo
("Global variable 'test' is not set.<P>\n");
}
?>
------------------------------------------------------------------
John Parker email: jparker@itchannel.net
Internet Project Manager/Software Engineer web:www.itchannel.net
itCHANNEL International Ltd. tel: +44 (0) 1202 291939