Here is my class:
<?php
class myClass {
private $a = 1;
private $b = array(
'a' => $this->a
);
public function getB() {
return $this->b;
}
}
$myclass = new myClass();
var_dump($myclass->getB());
I want to access variable $a in variable $b. But this shows this error:
( ! ) Parse error: syntax error, unexpected '$this' (T_VARIABLE) in C:\xampp\htdocs\test1.php on line 5
$thisis not defined when class variables are declared. After__constructis called you can access$this