从扩展类获取类名 [英] Get class name from extended class

查看:72
本文介绍了从扩展类获取类名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从扩展类中获取顶级类的名称,而无需从顶级类中进行设置.参见下面的示例,我想从Base获取"Foo".我知道我可以从Foo设置一个变量,但希望跳过多余的步骤.

Is it possible to get the name of the top level class from an extended class, without setting it from the top level class. See example below, I would like to get 'Foo' from Base. I know I could set a variable from Foo, but hoping to skip the extra step.

谢谢.

class Base {

    function __construct() {

        echo '<p>get_class: '.get_class().'</p>';
        echo '<p>__CLASS__: '.__CLASS__.'</p>';

    }

}


class Foo extends Base {

}


$test = new Foo();

(PHP 5.2.4 +)

(PHP 5.2.4+)

推荐答案

使用:

get_class($this);

这篇关于从扩展类获取类名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆