Created
December 6, 2011 07:22
-
-
Save barkerja/1437182 to your computer and use it in GitHub Desktop.
PHP Late Static Binding
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 Foo { | |
public static function name() { | |
echo __CLASS__; | |
} | |
} | |
class Bar extends Foo { | |
} | |
Foo::name(); | |
Bar::name(); |
Instead of CLASS, you must call get_called_class() which supports late static binding thus providing the expected results
of “FooBar”
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Expected Results:
FooBar
Actual Results:
FooFoo