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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With