未定義的常量問題不是一個新問題,我已經嘗試過Google,並且發現了一百萬個涉及缺少引號的數組的答案,這不是我的解決方案。我正在學習使用PHP進行OOP編碼,這實際上是我使用PHP開始的幾個小時。這是我創建的班級。使用未定義的常量 - 學習OOP PHP
class template {
var $page;
function __construct() {
$this->page = 'home';
}
function getHeader($header = 'header') {
include ('template/'.$header.'.php');
}
function getFooter($footer = 'footer') {
include ('template/'.$footer.'.php');
}
function setPage($page = 'home') {
$this->page = $page;
}
function getPage() {
if(page === 'home') {
include('template/home.php');
} else {
include('template/'.$this->page.'.php');
}
}
}
這就是我如何實例化它。
include('class.template.php');
$template = new template();
$template->getHeader();
if(isset($_GET['page'])) {
$template->setPage($_GET['page']);
}
$template->getPage();
$template->getFooter();
當然的錯誤 - 注意:使用未定義的常量頁的 - 假設「頁」在/Applications/MAMP/htdocs/titan-up/class.template.php在線24
這很顯然,我應該馬上發現我做錯了,但已經很晚了,而且我很茫然。任何幫助是極大的讚賞。
編輯:任何使學習過程更輕鬆的鏈接將不勝感激。我已經閱讀了PHP手冊,並且在PHP中有強大的背景,但不是OOP。從這個
參見http://stackoverflow.com/questions/2941169/what-does-the-php-error-message-notice-use-of-undefined-constant-mean –