note 86742 deleted from language.variables.scope by danbrown
| From: | danbrown@php.net | Date: | Sun, 02 Nov 2008 15:29:48 +0000 |
| Subject: | note 86742 deleted from language.variables.scope by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-146055@lists.php.net to get a copy of this message | ||
Note Submitter: rom
----
Qualifying a variable with the keyword global has a tricky but
undocumented effect -- it doesn't merely allow code in a function to access global variable,
but it actually creates global variables. This should have been clearly described in the manual.
Reproduce code:
---------------
function main() {
global $num;
$num = 10;
test();
}
function test()
{
$number = $GLOBALS['num'];
echo "num = $number";
}
I expected this result:
num =
because $num isn't declared outside all functions
but got this:
num = 10