我有一個奇怪的問題,我在父類中設置了值,但無法在擴展父類的子類中訪問這些值。訪問子類中的父屬性值
class Parent
{
protected $config;
public function load($app)
{
$this->_config();
$this->_load($app);
}
private function _config()
{
$this->config = $config; //this holds the config values
}
private function _load($app)
{
$app = new $app();
$this->index;
}
}
class Child extends Parent
{
public function index()
{
print_r($this->config); // returns an empty array
}
}
$test = new Parent();
$test->load('app');
當我這樣做時,我得到一個空的數組打印出來。但如果我這樣做,那麼我可以訪問這些配置值。
private function _load($app)
{
$app = new $app();
$app->config = $this->config
$app->index;
}
和
class Child extends Parent
{
public $config;
....
}
然後我可以從父訪問配置數據。
什麼是'app'類? –
應用程序類其子類 – Eli