Because it is impossible to define properties to use expressions.
Do initialization of properties in the class constructor.
Could you elaborate about this design:
class SimpleClass{
public $now = ";
function __construct() {
$now = date("Y-m-d");
}
public function display_now() {
echo $this->now;
var_dump($this->now);
}
}
$b = new SimpleClass();
$b->display_now();
- Why can't he override it in the constructor and outputs string(0) "" - Clovis_Gulgowski43 commented on July 9th 19 at 10:36
: because in the constructor you need to write not $now, $this->now - Marcus.Wolff commented on July 9th 19 at 10:39
: and Yes, I'm lame, get used to OOP in any way, thank you )) - Clovis_Gulgowski43 commented on July 9th 19 at 10:42
- Why can't he override it in the constructor and outputs string(0) "" - Clovis_Gulgowski43 commented on July 9th 19 at 10:36