Reputation: 393
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;
}
I get Parse error: syntax error, unexpected T_VARIABLE error on the last line. Any thoughts?
Upvotes: 1
Views: 482
Reputation:
You cannot use $this
on property's
Using from following solution:
<?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;
}
}
Upvotes: 0
Reputation: 4039
You can't use $this
keyword during initialisation.
You need to use a constructor if you need so.
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;
}
}
Upvotes: 1