As other answers noted, this is a problem with PHP that has not been resolved to date, but if it is a "side effect" of var_dump() , I'm not sure.
echo ((array) new DateTime())['date'];
I am sure that if the DateTime properties that were intended to be used by us would be available. But, like many inner classes, they are not, and you should not rely on "hacker" or "buggy" methods to fix the code. Instead, you should use their API .
echo (new DateTime())->format('Ymd H:i:s');
If you are not satisfied, you can extend the class or use Carbon , which extends it for you.
echo (new Carbon())->toDateTimeString();
If you know how var_dump() creates fake object output, see __debugInfo()
Xorifelse Dec 22 '16 at 3:26 2016-12-22 03:26
source share