What is the best approach to accessing a variable out of scope, see my current method:
// Define API
require_once( 'api.php' );
global $myapi;
$myapi = new LazyAPI( 'My API', 'myapi' );
class Content {
function DoAction() {
global $myapi;
$key = $myapi->someFunc() . "-key";
}
}
$content = $myapi->Content(); // LazyAPI is a class that loads classes in other files using reflection
$content->DoAction();
The issue I am facing (and am unable to test until further on) is redeclaring or reusing $myapi
in other files. I have only used the global
access modifer because I know it works, and I don't know if there is a better alternative. The idea is to be able to declare multiple $myapi
variables and only accessible within the scope of the main file.