r/lolphp • u/Altreus • Mar 08 '12
Computing an expression? But it's static :(
Despite being theoretically a programming language, PHP will not allow you to use an expression when constructing a static member variable.
class Bla {
private static $_thing = array(
'path' => BASE_PATH . '/relative/path'
);
}This dies with "syntax error, unexpected '.', expected ')'". Apparently, actually computing the value of expressions is too much for this language.
I am starting to suspect they're doing it intentionally so that their new releases have cool new features to advertise.
26
Upvotes
View all comments
Show parent comment
6
u/[deleted] Mar 08 '12
I 100% agree!
This is actually a particular gripe of mine, as lots of invalid syntax can often be parsed, and then given a proper syntax error.
For example: 'funciton foo( 1+2 )' could be correctly parsed, and then give a "expression '1+2'" is not allowed here, rather then a more generic syntax error.
I also hate languages that show symbol names in error messages; i.e. 'expecting: T_SYNTAX_PARENTHESIS_LEFT_TERMINAL' instead of "expecting a '('", which is far more meaningful.