Skip to content

Instantly share code, notes, and snippets.

@Pym
Created December 9, 2013 11:31
Show Gist options
  • Save Pym/7870904 to your computer and use it in GitHub Desktop.
Save Pym/7870904 to your computer and use it in GitHub Desktop.
<?php
$date = new \DateTime('now');
var_dump($date);
// object(DateTime)[594]
// public 'date' => string '2013-12-09 12:04:17' (length=19)
// public 'timezone_type' => int 3
// public 'timezone' => string 'Europe/Paris' (length=12)
var_dump($date->date);
// ContextErrorException: Notice: Undefined property: DateTime::$date
// Solutions :(
get_object_vars($date)['date'];
$date->format('Y-m-d H:i:s');
@C-Duv
Copy link

C-Duv commented Dec 11, 2013

@Pym: I don't get any ContextErrorException on var_dump($date->date); (PHP v5.5):

string '2013-12-11 21:19:46' (length=19)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment