note 30679 added to reserved.variables
| From: | LouisGreen at pljg dot freeserve dot co dot uk | Date: | Tue, 25 Mar 2003 16:23:27 +0000 |
| Subject: | note 30679 added to reserved.variables | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-45802@lists.php.net to get a copy of this message | ||
It seems that when you wish to export a varible, you can do it as return $varible, return an
array(), or globalise it. If you return something, information for that varible can only travel one
way when the script is running, and that is out of the function.
function fn() {
$varible = "something";
return $variable;
}
echo fn();
OR
$newvariable = fn();
Although if global was used, it creates a pointer to a varible, whether it existed or not, and makes
whatever is created in the function linked to that global pointer. So if the pointer was global
$varible, and then you set a value to $varible, it would then be accessible in the global scope. But
then what if you later on in the script redefine that global to equal something else. This means
that whatever is put into the global array, the information that is set in the pointer, can be set
at any point (overiden). Here is an example that might make this a little clearer:
function fn1() {
global $varible; // Pointer to the global array
$varible = "something";
}
fn1();
echo $varible; // Prints something
$varible = "12345";
echo $varible; // Prints 12345
function fn2() {
global $varible; // Pointer to the global array
echo $varible;
}
fn2(); // echos $varible which contains "12345"
Basically with the global array, you can set it refer to something already defined or set it to
something, (a pointer) such as varible you plan to create in the function, and later possibly over
ride the pointer with something else.
--
http://www.php.net/manual/en/reserved.variables.php
http://master.php.net/manage/user-notes.php?action=edit+30679
http://master.php.net/manage/user-notes.php?action=delete+30679
http://master.php.net/manage/user-notes.php?action=reject+30679