Adds late static binding to PHP reference

This commit is contained in:
Brett Taylor 2015-10-16 12:04:17 +13:00
parent 66bc42e31b
commit 6c14f507c2

View File

@ -693,6 +693,43 @@ use My\Namespace as SomeOtherNamespace;
$cls = new SomeOtherNamespace\MyClass();
/**********************
* Late Static Binding
*
* /
class ParentClass {
public static function who() {
echo "I'm a " . __CLASS__ . "\n";
}
public static function test() {
// self references the class the method is defined within
self::who();
// static references the class the method was invoked on
static::who();
}
}
ParentClass::test();
/*
I'm a ParentClass
I'm a ParentClass
*/
class ChildClass extends ParentClass {
public static function who() {
echo "But I'm " . __CLASS__ . "\n";
}
}
ChildClass::test();
/*
I'm a ParentClass
But I'm ChildClass
*/
/**********************
* Error Handling
*