Skip to content

Instantly share code, notes, and snippets.

@wkm
Created February 3, 2012 14:20
Show Gist options
  • Save wkm/1730377 to your computer and use it in GitHub Desktop.
Save wkm/1730377 to your computer and use it in GitHub Desktop.
<?
class A {
static $instance = null;
public static function getInstance(){
if(is_null(self::$instance)){
self::newInstance();
}
return self::$instance;
}
public static function newInstance(){
self::$instance = static::createInstance();
}
public static function createInstance(){
return "from A";
}
}
class B extends A {
public static function createInstance(){
return "from B";
}
}
class C extends A {
public static function createInstance(){
return "from C";
}
}
print B::getInstance() . "\n";
print C::getInstance() . "\n";
//prints
//from B
//from B
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment