解析错误:语法错误,意外的T
Class Config{
public $levels = 10;
public $points_difference = 100;
public $diff_level = 3;
public $timer_seconds = 60;
public $maxBonus = 0;
public $maxScore = 0;
public $maxTotalScore = 0;
public $pointsLevel = $this->points_difference * $this->diff_level;
}
我得到Parse错误:语法错误,最后一行出现意外的T_VARIABLE错误。 有什么想法吗?
初始化期间不能使用$this
关键字。
如果您需要,您需要使用构造函数。
Class Config{
public $levels = 10;
public $points_difference = 100;
public $diff_level = 3;
public $timer_seconds = 60;
public $maxBonus = 0;
public $maxScore = 0;
public $maxTotalScore = 0;
public $pointsLevel; //no initialisation here
function __construct() {
$this->pointsLevel = $this->points_difference * $this->diff_level;
}
}
你不能在财产上使用$this
使用以下解决方案:
<?php
class Config
{
public $levels = 10;
public $points_difference = 100;
public $diff_level = 3;
public $timer_seconds = 60;
public $maxBonus = 0;
public $maxScore = 0;
public $maxTotalScore = 0;
public $pointsLevel;
public function __construct()
{
$this->$pointsLevel = $this->points_difference * $this->diff_level;
}
}
链接地址: http://www.djcxy.com/p/69603.html