Предопределённые переменные
PHP Manual

$GLOBALS

$GLOBALSReferences all variables available in global scope

Описание

An associative array containing references to all variables which are currently defined in the global scope of the script. The variable names are the keys of the array.

Примеры

Пример #1 $GLOBALS example

<?php
function test() {
    
$foo "local variable";

    echo 
'$foo in global scope: ' $GLOBALS["foo"] . "\n";
    echo 
'$foo in current scope: ' $foo "\n";
}

$foo "Example content";
test();
?>

Результатом выполнения данного примера будет что-то подобное:

$foo in global scope: Example content
$foo in current scope: local variable

Примечания

Замечание:

Это 'суперглобальная' или автоматическая глобальная переменная. Это просто означает что она доступна во всех контекстах скрипта. Нет необходимости выполнять global $variable; для доступа к ней внутри метода или функции.

Замечание: Variable availability

Unlike all of the other superglobals, $GLOBALS has essentially always been available in PHP.


Предопределённые переменные
PHP Manual