mač*_*ček 6 php singleton design-patterns
我正在尝试子类化使用单例模式的类,并使用子类填充实例.
我好像有点麻烦.
class Singleton {
static private $instance;
static public function instance(){
if(is_null(self::$instance)){
self::$instance = new self();
}
return self::$instance;
}
private function __construct(){}
}
class MySingleton extends Singleton {
}
echo get_class(MySingleton::instance()); //=> Singleton
//=> I'm hoping to see MySingleton
Run Code Online (Sandbox Code Playgroud)