I haven't found it anywhere else in the manual, so I'll make a note of it here - PHP will automatically replace any dots ('.') in an incoming variable name with underscores ('_'). So if you have dots in your incoming variables, e.g.:
example.com/page.php?chuck.norris=nevercries
you can not reference them by the name used in the URI:
//INCORRECT
echo $_GET['chuck.norris'];
instead you must use:
//CORRECT
echo $_GET['chuck_norris'];Претходно дефинирани променливи
Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.
Претходно дефинирани променливи
Референца за `language.variables.predefined.php` со подобрена типографија и навигација.
Претходно дефинирани променливи
PHP обезбедува голем број на претходно дефинирани променливи. PHP исто така обезбедува дополнителен сет на претходно дефинирани низи кои содржат променливи од веб серверот (ако е применливо), околината и корисничкиот влез. Овие низи се автоматски достапни во секој опсег. Од оваа причина, тие често се познати како "суперглобални". (Не постои механизам во PHP за суперглобални дефинирани од корисникот.) Погледнете го списокот на суперглобални интерполација на низи
Забелешка: Променливи на променливи
Суперглобалните не можат да се користат како (низа) во рамките на функции или методи на класа.
Ако одредени променливи во variables_order не се поставени, соодветните PHP претходно дефинирани низи исто така остануваат празни.
Белешки од корисници 3 белешки
- Security Issue and workaround -
If You use "eval()" to execute code stored in a database or elsewhere, you might find this tip useful.
Issue:
By default, all superglobals are known in every function.
Thus, if you eval database- or dynamically generated code (let's call it "potentially unsafe code"), it can use _all_ the values stored in _any_ superglobal.
Workaround:
Whenever you want to hide superglobals from use in evaluated code, wrap that eval() in an own function within which you unset() all the superglobals. The superglobals are not deleted by php in all scopes - just within that function. eg:
function safeEval($evalcode) {
unset($GLOBALS);
unset($_ENV);
// unset any other superglobal...
return eval($evalcode);
}
(This example assumes that the eval returns something with 'return')
In addition, by defining such a function outside classes, in the global scope, you'll make sure as well that the evaluated ('unsafe') code doesn't have access to the object variables ($this-> ...).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 when accessing 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.