在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
参考:https://www.cnblogs.com/water0729/p/5803217.html <?php class foo { static public function test() { echo "foo.__CLASS__:".__CLASS__."\n"; echo "foo.get_class:".get_class()."\n"; echo "foo.get_called_class:".get_called_class()."\n"; } } class bar extends foo { } foo::test(); echo "\n"; bar::test(); ?> //结果 foo.__CLASS__:foo foo.get_class:foo foo.get_called_class:foo foo.__CLASS__:foo foo.get_class:foo foo.get_called_class:bar 1.__CLASS__:获取当前的类名 2.get_class():返回对象的类名 3.get_called_class():后期静态绑定("Late Static Binding")类的名称,即静态方法调用者的类名 <?php //通过get_called_class实现单例模式 class Singleton{ private static $instance; public static function getInstance() { $class_name = get_called_class(); if (isset(self::$instance[$class_name])) { return self::$instance[$class_name]; } self::$instance[$class_name] = new $class_name; return self::$instance[$class_name]; } } ?>
|
2022-08-17
2022-11-06
2022-08-17
2022-07-29
2022-07-29
请发表评论