Unbelievable PHP limitation of the day

By Adrian Smith10 Dec 2007100 words1 mins to read

If one defines a class with the member variable:

protected static $bytes = 12582912;

then that's fine. However if one defines it as:

protected static $bytes  = 12*1024*1024; // 12 MB

then that gives a compile error:

Parse error: syntax error, unexpected '*', expecting ',' or ';'

I know of no other language that I've ever programmed (i.e. including BASIC, and C) where you can write a value, but you can't write an expression.

How broken is that!

Putting spaces around the *, or adding brackets around the whole expression, does not help.

(PHP 5.2.0)

This article was written by Adrian Smith on 10 Dec 2007

Follow me: Facebook | Twitter | LinkedIn | Email

More on: PHP | FAIL | Language Design