maybe its late or something, but this is freaking me out. Basicly im writing framework for the excercise, trying to get my oop skill rolling, but im kinda stuck. I think i maybe hit a rookie err, that i just dont know of :)
So i have a bootstrap class which initializes the whole program. I creates a controller, in which you can call an app (or model if you prefer). All controllers and apps are sub classes of an initialization class, that implements the singleton pattern. This i because i would like to use the construct function for other init stuff based on the given controller/app.
Now the problem is, when i try to init an app from within the controller, the instance var is already set to the controller object (which i thought was null). If im not clear enough, here is the code in a very simplified and raw form:
<?php
final class Bootstrap {
public function __construct() {
$controller = Controller::init();
$controller->index();
}
}
abstract class Initialization {
private static $_instance = NULL;
final public static function init() {
$c = get_called_class();
var_dump(self::$_instance);
self::$_instance = new $c();
return self::$_instance;
}
final protected function app($app) {
$app::init();
}
}
final class Form extends Initialization { }
final class Controller extends Initialization {
final public function Index() {
$this->app('form');
}
}
$bootstrap = new Bootstrap();
?>
The output is
null
object(Controller)[2]
Im confused why is the instance already set in the form app?? I thought it inherited it's "own" static instance var??