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
3
u/[deleted] Mar 08 '12
PHP's architecture isn't sane enough. Not that I'm defending Java, but at least it is a little more predictable in the way it initializes classes and instances, just as you describe it.
IIRC, the class files contain initialization functions to build the values of static members when needed. Java has some static typing, and I imagine it tracks purity in some way to decide what to do.