2009-03-04 29 views
0

這裏是我的代碼部分爲什麼在類常量內指定一個定義的常量會引發錯誤?

define('DIR_APP', 'app/'); 

class Questions 
    { 


     const QUESTIONS_FILE = DIR_APP . 'questions.xml'; 
    } 

似乎當我走define()倒是不斷從我的類常量聲明的,它工作正常。但是,當我添加它,它拋出這個錯誤:

Parse error: syntax error, unexpected '.', expecting ',' or ';' in /home/public_html/app/classes/Questions.class.php on line 7 

那麼,怎樣才能讓我的「define()在那裏的d常數?我認爲它不能正確查找DIR_APP,認爲它可能是在課堂上定義的。我如何才能解決它全球?

謝謝

回答

4

它不能完成。從http://www.php.net/manual/en/language.oop5.constants.php

報價:

"The value must be a constant expression, not (for example) a variable, a class member, result of a mathematical operation or a function call"

我想你可以

define('QUESTIONS_FILE', DIR_APP . 'questions.xml');

但是這是全球性的。

0

以前從未嘗試過。 Zend Studio現在給我提供了一個問題,我自己來看看。如何嘗試這個雖然...

const QUESTIONS_FILE = constant("DIR_APP") . 'questions.xml'; 
+0

它在括號中ch咽:( – alex 2009-03-04 06:29:52

+0

Gah!你運行的是什麼版本的PHP? – 2009-03-04 06:41:20