note 12787 deleted from language.variables.scope by cmb
| From: | cmb@php.net | Date: | Sun, 27 Oct 2019 08:28:29 +0000 |
| Subject: | note 12787 deleted from language.variables.scope by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212777@lists.php.net to get a copy of this message | ||
Note Submitter: carpathia_uk at mail dot com
----
On confusing aspect about global scope...
If you want to access a variable such as a cookie inside a function, but theres a chance it may not
even be defined, you need to access it using he GLOBALS array, not by defining it as global.
This wont work correctly....
<?php
function isLoggedin()
{
global $cookie_username;
if (isset($cookie_username)
echo "blah..";
}
?>
This will..
<?php
function isLoggedin()
{
if (isset($GLOBALS["cookie_username"]))
echo "blah..";
}
?>