Home > Article > Backend Development > Why is this still 2 after using the constructor?
Why is the result 2 instead of 5?
<code>class a{ public $age=2; public function __constrator(){ $this->age=$age+3; } } $k=new a(); echo $k->age;</code>
Why is the result 2 instead of 5?
<code>class a{ public $age=2; public function __constrator(){ $this->age=$age+3; } } $k=new a(); echo $k->age;</code>
It made me laugh __constrator
became __construct
and $this->age=$this->age+3;
<code>class a{ public $age=2; public function __constrator(){ $this->age=$this->age+3; // 这里 } } $k=new a(); echo $k->age;</code>
This one is missing $this->
<code> $this->age=$this->age+3;</code>