PHP继承中$this的问题

在父类中的构造函数中使用$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 的对象
   }
}
 




原文地址:https://www.cnblogs.com/w10234/p/5415859.html