douqiao6015 2014-10-27 11:20
浏览 29
已采纳

php 5.4不接受类常量

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?

  • 写回答

1条回答 默认 最新

  • dongtong5242 2014-10-27 11:27
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退