I have a base class, which includes all other files. I can access this class (it is public) throughout my entire application (by way of base::$var or base::function()).
One of the functions of this base class is to load additional frameworks. One of the frameworks looks like the following (simplified) – based off a singleton that I saw here on SO.
<?php
class someOtherFramework{
public static $site = array();
public static function Instance() {
static $inst = null;
if ($inst == null) {
$inst = new someOtherFramework();
}
return $inst;
}
private function __construct() {
}
}
base::createInstance('blah', 'someOtherFramework');
?>
The call to base::createInstance is the following:
public static function createInstance($variable, $class){
if (class_exists($class)){
$variable = $class::Instance();
}
}
The goal is that I can access $blah in the same way that I do $base. Is it possible? Does this make sense? If not, what’s the best way to provide access to a class another developer might want to use?
the only way of accessing your ‘blah’ variable, is if it was a global. which isn’t really OOP design.
Maybe you should look into creating a Registry class which is passed around by reference that contains all of those variables? For myself, I find it neater to do that (and much less of a nightmare thank you Eclipse IDE!) – and personally, I don’t like Singleton classes
… though, the code you posted, doesn’t exactly make sense. Can you post more details?