PHP7常量const修饰符syntax error, unexpected ‘const‘ (T_CONST), expecting variable (T_VARIABLE)
2022-07-28 15:20:24
120
{{single.collect_count}}

错误代码

语法解析错误: syntax error, unexpected 'const' (T_CONST), expecting variable (T_VARIABLE)

代码

class Psr16Cache implements CacheInterface, PruneableInterface, ResettableInterface{use ProxyTrait;private const METADATA_EXPIRY_OFFSET = 1527506807;private $createCacheItem;private $cacheItemPrototype;public function __construct(CacheItemPoolInterface $pool){

错误原因  PHP版本太低,常量修饰符7.1才支持

PHP 7.1 之前的类常量是不允许添加可见性修饰符的,此时类常量可见性相当于 public。PHP 7.1 为类常量添加了可见性修饰符支持特性。总的来说,可见性修饰符使用范围如下所示:

函数/方法:public、private、protected、abstract、final

  • 类:abstract、final
  • 属性/变量:public、private、protected
  • 类常量:public、private、protected


 

回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}