Created
February 21, 2012 16:55
-
-
Save raphaeldealmeida/1877353 to your computer and use it in GitHub Desktop.
PHP 5.3 - Late Static Binding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Foo{ | |
protected static function speak(){ | |
echo __METHOD__, "\n\r"; | |
return 'Hi'; | |
} | |
public static function sayHi(){ | |
//return self::speak(); // PHP 5.2 <= | |
return static::speak(); //PHP 5.3 | |
} | |
} | |
class Bar extends Foo { | |
protected static function speak(){ | |
echo __METHOD__, "\n\r"; | |
return 'Hello'; | |
} | |
} | |
/* | |
output: | |
Bar::speak | |
Hello | |
*/ | |
echo Bar::sayHi(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment