Created
December 9, 2013 11:31
-
-
Save Pym/7870904 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'); |
he doesn't want to do a ->format()
:D
@luxifer: 👍
@j0k3e: my DateTime object already contains a proper formatted date string, but for an obscure reason, I can't access it directly (even if its visibility is public). I was looking for a better way to access it than get_object_vars(), but it looks like that it's the best solution.
@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
What the purpose of
get_object_vars
?It works great without: http://3v4l.org/vWOep