Skip to content

Instantly share code, notes, and snippets.

@rming
Created June 9, 2017 07:24
Show Gist options
  • Save rming/1958aacae57cb0395cae6fafd496bc5c to your computer and use it in GitHub Desktop.
Save rming/1958aacae57cb0395cae6fafd496bc5c to your computer and use it in GitHub Desktop.
php后期静态绑定
<?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