note 32587 added to reserved.variables
| From: | joe at heritagecreations dot com | Date: | Mon, 02 Jun 2003 03:07:36 +0000 |
| Subject: | note 32587 added to reserved.variables | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-49548@lists.php.net to get a copy of this message | ||
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.
----
Manual Page -- http://www.php.net/manual/en/reserved.variables.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32587
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32587&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32587&report=yes