我想創建一個類來存儲許多地方使用的多語言詞彙的小列表,我想要替換程序中當前使用的大量'include'語句。這是我在想什麼(它不是全功能的)。你能幫助我做出工作並使用適當的面向對象構造。設置詞彙列表的PHP OO類
class VocabClass{
public $term = array();
public function __construct(){
// my vocabulary...
$this->term['hello']['E'] = 'hello';
$this->term['hello']['F'] = 'bonjour';
$this->term['goodbye']['E'] = 'goodbye';
$this->term['goodbye']['F'] = 'aurevoir';
}
}
class Program{
public $vocab;
function __construct(){
$vocab = new VocabClass();
// this works
echo $vocab->term['hello']['F'];
}
function Main() {
// this doesn't work
echo $vocab->term['hello']['E'];
echo $this->term['hello']['E'];
}
}
$myProgram = new Program();
$myProgram->Main();
?>