1
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?

1
  • you should write this in constructor. public $pointsLevel = $this->points_difference * $this->diff_level; Commented Apr 25, 2014 at 6:42

2 Answers 2

1

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;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

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;
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.