how to make objects globally accessible?
- by fayer
i have this code:
class IC_Core {
/**
* Database
* @var IC_Database
*/
public static $db = NULL;
/**
* Core
* @var IC_Core
*/
protected static $_instance = NULL;
private function __construct() {
}
public static function getInstance() {
if ( ! is_object(self::$_instance)) {
self::$_instance = new self();
self::initialize(self::$_instance);
}
return self::$_instance;
}
private static function initialize(IC_Core $IC_Core) {
self::$db = new IC_Database($IC_Core);
}
}
but when i wanna access IC_Database with:
$IC = IC_Core::getInstance();
$IC->db->add() // it says that its not an object.
i think the problem lies in self::$db = new IC_Database($IC_Core);
but i dont know how to make it work.
could someone give me a hand=)
thanks!