Here is part of my code
define('DIR_APP', 'app/');
class Questions
{
const QUESTIONS_FILE = DIR_APP . 'questions.xml';
}
Seems when I take the define()
'd constant out of my class constant declaration, it works fine. But when I add it it throws this error:
Parse error: syntax error, unexpected '.', expecting ',' or ';' in /home/public_html/app/classes/Questions.class.php on line 7
So how can I get my define()
'd constant in there? I assume it is not correctly looking up the DIR_APP
thinking it might of been defined within the class. How do I get it to resolve it globally?
Thank you
It can't be done.
Quote from 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"
I think you could
define('QUESTIONS_FILE', DIR_APP . 'questions.xml');
but that is global.
Never tried that before. Zend Studio is giving me an issue at the moment to look at it myself. How about trying this though...
const QUESTIONS_FILE = constant("DIR_APP") . 'questions.xml';