douqianxun8540 2016-01-30 17:50
浏览 27

你能知道固有的孩子名字吗?

I have a clase Base in PHP for inherit it to many children classes, managing errors into Base class, I try to print in screen where the error occurs, Can I get the child class name to show in the error during the Exception in Base parent Class?

  • 写回答

2条回答 默认 最新

  • dongyuqi3808 2016-01-30 17:59
    关注

    Yes you can using get_class()

    class Base{
        public function printBase(){
            echo get_class($this);
        }
    }
    
    class Ext extends Base{}
    
    $ext = new Ext();
    $ext->printBase(); //Output: Ext
    
    评论

报告相同问题?