static members - Class constant not accepted by php 5.4 -
static members - Class constant not accepted by php 5.4 -
i have class constant
const date_regex = '@^(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$@';
which want utilize in static array part of string:
public static $rules = [ 'startdate' => ['required','regex:' . self::date_regex], ];
both of lines part of same class.
on dev machine (php 5.6) works fine, on staging server (php 5.4) throws next error:
syntax error, unexpected '.', expecting ']'
how can rewrite php 5.4 compatible?
php 5,4 not allow expressions in class properties declaration.
such feature has been introduced php 5.6 http://php.net/migration56.new-features#migration56.new-features.const-scalar-exprs
php static-members class-constants
Comments
Post a Comment