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?

4

1 回答 1

4

PHP 5,4 不允许在类属性声明中使用表达式。

PHP 5.6 http://php.net/migration56.new-features#migration56.new-features.const-scalar-exprs引入了此类功能

于 2014-10-27T11:27:30.183 回答