Syntax error while defining an array as a property of a class

You cannot use non-constant values while initializing class properties in PHP versions earlier than 5.6.
These are initialized at compile time, at which PHP will do no calculations or execute any code. (5 * (1024 * 1024)) is an expression that requires evaluation, which you cannot do there. Either replace that with the constant value 5242880 or do the calculation in __construct.

PHP 5.6, introduced in 2014, allows “constant scalar expressions” wherein a scalar constant or class property can be initialized by an evaluated expression in the class definition rather than the constructor.

Leave a Comment