我正在尝试访问扩展它的子类中的父类 __construct 属性,但是不确定如何执行此操作,因为我尝试了多种方法并且没有给我预期的结果。
所以我有一个 baseController 和一个扩展它的 indexController,我希望能够直接访问子控制器中父级的属性。
$config = ['site' => 'test.com'];
class baseController {
public function __construct($config){
$this->config = $config;
}
}
class indexController extends baseController {
public function __construct(){
parent::__construct(); // doesnt seem to give any outcome
}
public static function index() {
var_dump($this->config); // need to access within this method
}
}
$app->route('/',array('indexController','index')); // the route / would call this controller and method to return a response