Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否有更好/更短的方法来编写whoAmI以下代码中的方法?仅仅为了获取静态类的名称而创建一个新对象似乎有点不必要。
whoAmI
<?php abstract class baseClass { static function whoAmI() { echo get_class(new static); // Making a new class just to get its name??? } }
试试get_called_class()。
get_called_class()
http://php.net/manual/en/function.get-call-class.php