The variable should be defined in Registry class which is sort of pattern.
Working demo
Example of Registry
class Registry {
private static $registry = array();
private function __construct() {} //the object can be created only within a class.
public static function set($key, $value) { // method to set variables/objects to registry
self::$registry[$key] = $value;
}
public static function get($key) { //method to get variable if it exists from registry
return isset(self::$registry[$key]) ? self::$registry[$key] : null;
}
}
Usage
To register object you need include this classn
$registry::set('debug_status', $debug_status); //this line sets object in **registry**
To get the object you can use get method
$debug_status = $registry::get('debug_status'); //this line gets the object from **registry**
This is solution that every object/variable can be stored in. For such purpose as you wrote it's good to use simple constant and define()
.
My solution is good for every kind of object that should be accessed from anywhere in application.
Edit
Removed singleton and make get, set methods as static as @deceze suggested.