在父类中的构造函数中使用$this , 这是$this指的是正在实例化的子类对象,不管是parent还是继承调用父类的构造函数.

如:

class CompanyController extends CommonController{ }

class CommonController extends Controller { }

abstract class Controller {
   public function __construct() {
if(method_exists($this,'_initialize'))
$this->_initialize(); //此时$this指向子类CompanyController 的对象
   }
}

 

 

 




相关文章:

  • 2021-06-03
  • 2021-12-05
  • 2021-04-06
  • 2022-12-23
  • 2021-11-17
  • 2021-09-26
  • 2021-07-26
  • 2021-09-10
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-27
  • 2021-09-27
  • 2022-01-09
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案