Last active
August 29, 2015 13:58
-
-
Save papayasoft/10353046 to your computer and use it in GitHub Desktop.
Late static binding in PHP 5.3: The difference between self:: and static::
This file contains 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 MyBase | |
{ | |
public static function myMethod() | |
{ | |
return 'Called MyBase::myMethod()'; | |
} | |
public static function doSomethingSelf() | |
{ | |
return self::myMethod(); | |
} | |
public static function doSomethingStatic() | |
{ | |
return static::myMethod(); | |
} | |
} | |
class MyChild extends MyBase | |
{ | |
public static function myMethod() | |
{ | |
return 'Called MyChild::myMyMethod()'; | |
} | |
} | |
function o($s) | |
{ | |
echo $s . PHP_EOL; | |
} | |
o(MyChild::doSomethingSelf()); | |
o(MyChild::doSomethingStatic()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment