Is it possible to define a property of a PHP class and dynamically assign a value using the property inside the same class? Sort of:
class user {
public $firstname = "jing";
public $lastname = "ping";
public $balance = 10;
public $newCredit = 5;
public $fullname = $this->firstname.' '.$this->lastname;
public $totalBal = $this->balance+$this->newCredit;
function login() {
}
}
Productivity:
Parse error: syntax error, unexpected '$ this' (T_VARIABLE) on line 6
Is there something wrong in the above code? If yes, please help me, and if this is not possible, then what is a good way to do this?
source
share