How to get the name of child class from base class when an object of child class is created

前端 未结 4 509
被撕碎了的回忆
被撕碎了的回忆 2021-01-03 07:21

I want to get the name of my child class in the base class so that whenever an object of child class is created I get the name of the child class in my base class. Something

4条回答
  •  温柔的废话
    2021-01-03 07:37

    Well, just pass it explicitly then:

    class BaseClass{
    
      function __construct($tableName){
        // do stuff w/ $tableName
      }
    
    }
    
    class ChildClass extends BaseClass{
    
      function __construct(){
        parent::__construct('ChildClass');
      }
    
    }
    

提交回复
热议问题