Reputation: 2500
I need to define constant with value. I've tried to makes something like this:
class Foo {
const ARTICLES_KEY = $this->config->models->key->category;
}
But php says: syntax error, unexpected T_VARIABLE
I also tried to use static var, but it doesnt work.
How to make such thing properly?
Upvotes: 3
Views: 174
Reputation: 75629
You can't: http://www.php.net/manual/en/language.oop5.constants.php reads
It is possible to define constant values on a per-class basis remaining the same and unchangeable. Constants differ from normal variables in that you don't use the $ symbol to declare or use them.
The value must be a constant expression, not (for example) a variable, a property, a result of a mathematical operation, or a function call.
Upvotes: 3