Undefined global variable %s

Description

$GLOBALS is a superglobal that stores all the defined global variables. It yields this warning when trying to reach a global via one of its index.

Example

<?php

function foo() {
    echo $GLOBALS['a'];
}

foo();

?>

Literal Examples

  • Undefined global variable $a

  • Undefined global variable $GLOBALS

Solutions

  • Create the global with the global keyword before accessing it.