0

I have a class constant

const DATE_REGEX = '@^(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$@';

which I want to use in a static array as part of a string:

public static $rules = [
    'startdate' => ['required','regex:' . self::DATE_REGEX],
];

Both of those lines are part of the same class.

On my dev machine (PHP 5.6) this works fine, but on the staging server (PHP 5.4) this throws the following error:

syntax error, unexpected '.', expecting ']'

How can I rewrite this to be PHP 5.4 compatible?

Tom Macdonald
  • 6,433
  • 7
  • 39
  • 59

1 Answers1

4

PHP 5,4 does not allow for expressions in the class properties declaration.

Such feature has been introduced by PHP 5.6 http://php.net/migration56.new-features#migration56.new-features.const-scalar-exprs

tacone
  • 11,371
  • 8
  • 43
  • 60