class Foo
{
const MY_CONST = 'this is ' . 'data' ; //use of concatenation
public function __construct() {}
}
This gives error :
syntax error, unexpected ‘.’,
expecting ‘,’ or ‘;’
Then how I am supposed to use concatenation with constants?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Constants, should be, constants, it’s why you can’t work with expression here.
I don’t advise you the
runkit_constant_add()as it transforms a constant in a variable (or kind of) which is not the case and can be confusing.To resolve this issue, I usually “wrap” my constant in a protected array.
Use the constant to be used a key of an array, to have more complex expressions.
And let you use: