<slide title="Late Static Binding">

<break lines="1" />
<blurb fontsize="4em">http://php.net/lsb</blurb>

<example fontsize="1.4em" result='1' title=""><![CDATA[<?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();
?>
]]></example>

<example fontsize="1.4em" result="1" title="get_called_class"><![CDATA[<?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>';
?>]]></example>

</slide>
