Error in the class when you create a variable?

Actually:
e830ad90d990496882fca42d4eeb19b0.jpg

It is clear that if you make public $now = '2016-05-28'; then it works but how so?
July 9th 19 at 10:31
1 answer
July 9th 19 at 10:33
Solution
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

Find more questions by tags PHP