Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP expression for class constant

I'm trying to figure out why I get and exception with this code.

class Test {
    const test = "Two " .
                 "rows.";
}

I get an exception on the row containing the const:

Parse error: syntax error, unexpected '.', expecting ',' or ';' in /home/BZUMUL/prog.php on line X

I was going to switch to heredoc but then I got too curious so I couldn't stop trying to solve it.

like image 445
Marcus Johansson Avatar asked Dec 12 '25 12:12

Marcus Johansson


1 Answers

According to Class Constants:

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

So you cannot use an expression for the constant value.

like image 161
Joey Avatar answered Dec 14 '25 06:12

Joey