Created
June 9, 2017 07:24
-
-
Save rming/1958aacae57cb0395cae6fafd496bc5c to your computer and use it in GitHub Desktop.
php后期静态绑定
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 A { | |
public static $name = null; | |
public static function whoami() { | |
if (!static::$name) { | |
static::$name = get_called_class(); | |
} | |
return static::$name; | |
} | |
} | |
class B extends A { | |
public static $name = null; | |
} | |
class C extends A { | |
} | |
echo A::whoami(); | |
echo "\n"; | |
echo B::whoami(); | |
echo "\n"; | |
echo C::whoami(); | |
echo "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment