Why can't I access DateTime->date in PHP's DateTime class?

前端 未结 5 1552
醉梦人生
醉梦人生 2020-11-22 06:44

Using the DateTime class, if I try to run the following code:

$mydate = new DateTime();
echo $mydate->date;

I\'ll get back

5条回答
  •  南笙
    南笙 (楼主)
    2020-11-22 07:26

    Besides calling DateTime::format() you can access the property using reflection:

    getProperty('date');
    $date = $p->getValue($dt);
    

    This is slight faster than using format() because format() formats a timestring that has already been formatted. Especially if you do it many times in a loop.

    However this is not a regular behaviour of PHP. A bugreport has already been filed as @Nile mentioned in the comments above.

提交回复
热议问题