至於我想你既可以實例化類像這樣:引用類的類名::方法名()
$class = new className();
然後使用一個方法了,你就會只是做:
$class->myMethod();
或者,如果你想使用從類中的東西沒有實例它你可以這樣做:
className::myMethod();
我敢肯定,我公頃已經使用過,後者沒有任何問題,但爲什麼我會收到一個錯誤,指出:
Fatal error: Using $this when not in object context
我的代碼我使用叫它是:
// Display lists with error message
manageLists::displayLists($e->getMessage());
類如下。 。
class manageLists {
/* Constructor */
function __construct() {
$this->db_connection = connect_to_db('main');
}
function displayLists($etext = false, $success = false) {
// Get list data from database
$lists = $this->getLists();
......
}
function getLists() {
.........
}
}
我得到這個錯誤,從該行..
$lists = $this->getLists();
非常感謝! – Brett 2011-02-17 19:52:45