How do I get class name in PHP?

后端 未结 10 1997
名媛妹妹
名媛妹妹 2020-11-29 04:37
public class MyClass {

}

In Java, we can get class name with String className = MyClass.class.getSimpleName();

How to do this

10条回答
  •  隐瞒了意图╮
    2020-11-29 05:03

    I think it's important to mention little difference between 'self' and 'static' in PHP as 'best answer' uses 'static' which can give confusing result to some people.

    getStatic() . ', ' . $x->getSelf() . 
        ', Y: ' . $y->getStatic() . ', ' . $y->getSelf() . 
        ', Z: ' . $z->getStatic() . ', ' . $z->getSelf();
    

    Results:

    X: X, X
    Y: Y, X
    Z: Z, X
    

提交回复
热议问题