php expecting,php – 解析错误:语法错误,意外的’.’,expecting’,’或’;’

静态类属性在编译时被初始化.在初始化静态类属性时,不能使用常量TABLE_PREFIX与字符串文字连接,因为常量的值在运行时是不知道的.而是在构造函数中初始化它:

public static $user_table;

// Initialize it in the constructor

public function __construct() {

self::$user_table = TABLE_PREFIX . 'users';

}

// If you only plan to use it in static context rather than instance context

// (won't call a constructor) initialize it in a static function instead

public static function init() {

self::$user_table = TABLE_PREFIX . 'users';

}

Like any other PHP static variable, static properties may only be initialized using a literal or constant; expressions are not allowed. So while you may initialize a static property to an integer or array (for instance), you may not initialize it to another variable, to a function return value, or to an object.

PHP更新> = 5.6

PHP 5.6对表达式的支持有限:

In PHP 5.6 and later, the same rules apply as const expressions: some limited expressions are possible, provided they can be evaluated at compile time.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值