<?php
class A {
public static function who() {
echo __CLASS__;
}
public static function test() {
self::who(); // Normal class resolution
static::who(); // LSB
}
}
class B extends A {
public static function who() {
echo __CLASS__;
}
}
B::test();
?>
<?php
abstract class Singleton {
private static $instances = array();
final public static function getInstance() {
$className = get_called_class();
if(!isset(self::$instances[$className])) {
self::$instances[$className] = new $className();
}
return self::$instances[$className];
}
}
class foo extends Singleton { }
class bar extends Singleton { }
$a = foo::getInstance();
$b = foo::getInstance();
$c = bar::getInstance();
echo '<pre>';
var_dump($a);
var_dump($b);
var_dump($c);
echo '</pre>';
?>
object(foo)#471 (0) { } object(foo)#471 (0) { } object(bar)#478 (0) { }