For some reason, when defining:
function __construct() {
if(!isset($_GLOBALS["className"])) {
$_GLOBALS["className"] = new className;
}
return true;
}
$_GLOBALS["className"]->classMethod();
PHP for some reason states that $_GLOBALS[“className”] is undefined.
Oh, and the same also occurs even if I set the global value to something else, from within that class. I can test the value of the global through the construct or some other method, but not outside – it seems that the global is lost outside the class for some reason.
Is there a way to retain the global after declaring it from within an external class?
Any help is sincerely appreciated!
You want to use
$GLOBALSand not$_GLOBALS:http://php.net/manual/en/reserved.variables.globals.php
$_GLOBALSwill just be available in your function scope.