note 32587 deleted from reserved.variables by sniper
| From: | sniper@php.net | Date: | Tue, 21 Oct 2003 19:43:25 +0000 |
| Subject: | note 32587 deleted from reserved.variables by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-59066@lists.php.net to get a copy of this message | ||
Note Submitter: joe@heritagecreations.com
----
Variables that you use in include files are automatically made global. If your include file has
usernames and passwords assigned to a variable, those values are sitting in $GLOBALS. Accessing the
include file from within a function will keep the variables local to the function so that they
don't become globals.
Also, when assigining a predefined (global) variable to a variable you created, the new variable is
automatically made global. You don't need to pass the variable to a function, just declare it
as global within the function and the function will access the value.
function PrintRoot{
global $rootdirectory;
print $rootdirectory; // displays /home/user/dir
}
$rootdirectory = $_SERVER['DOCUMENT_ROOT'];
PrintRoot();
...
To view all the global variables:
print '<pre>';
print_r($GLOBALS);
PRINT '</pre>';
User variables are at the bottom of the list.