base.php:獲取來源於類屬性在基類
<?php namespace MyQuestion\Base;
abstract class BaseSetting
{
public function GetValue($setting)
{
return $this->$setting;
}
}
derived.php
<?php namespace MyQuestion\Configs;
use MyQuestion\Base;
class Settings extends BaseSetting
{
private $a = 'value 1';
private $b = 'value 2';
private $c = "value 3";
}
的index.php
$abc = new Settings();
$mySettings = $abc->GetValue('a');
我嘗試調試代碼。 $ this->設置中的某些內容被打破。我怎樣才能做到這一點?我有一些設置文件,我需要使用函數從它們中獲取值。我不想在每個設置文件中定義相同的功能。
'回報父母::的GetValue($設置)訪問屬性沒有按'如果屬性修飾符保持「私有」,則不起作用。 – paul