Using the DateTime
class, if I try to run the following code:
$mydate = new DateTime();
echo $mydate->date;
I'll get back this error message
Notice: Undefined property: DateTime::$date...
Which doesn't make sense because when running var_dump()
on the variable $mydate
, it clearly shows that this property exists and is publicly accessible:
var_dump($mydate);
object(DateTime)[1]
public 'date' => string '2012-12-29 17:19:25' (length=19)
public 'timezone_type' => int 3
public 'timezone' => string 'UTC' (length=3)
Is this a bug within PHP or am I doing something wrong? I'm using PHP 5.4.3.
This is a known issue.
For some reason, you're not supposed to be able to access the property but
var_dump
shows it anyways. If you really want to get the date in that format, use theDateTime::format()
function.