This is my code:
$date1 = new DateTime();
$date1->format('Y-m-d H:i:s');
echo $date1->date. ' while echoing date1';
It echoes only " while echoing date1", in other words $date1->date
is empty.
If I add dump date1 first like this:
$date1 = new DateTime();
$date1->format('Y-m-d H:i:s');
var_dump($date1);
echo $date1->date. ' while echoing date1';
I get
object(DateTime)[359]
public 'date' => string '2016-06-26 16:54:56.000000' (length=26)
public 'timezone_type' => int 3
public 'timezone' => string 'UTC' (length=3)
2016-06-26 16:54:56.000000 while echoing date1
which is what I want. This thing is getting me mad as it is completely unexpected.