I'm having trouble using the PHP DateTime class, and more specifically the DateTime::createFromFormat().
I get a date from a string, then try to instanciate a DateTime object, using DateTime::createFromFormat(). But, when I give this function a date that cannot exist, it is still working, returning me a valid DateTime object, with a valid date, which isn't the date I gave it.
Code example :
$badDate = '2010-13-03';
$date = DateTime::createFromFormat('Y-m-d', $badDate);
var_dump($date);
/*
object(DateTime)#284 (3) {
["date"]=>
string(19) "2011-01-03 10:01:20"
["timezone_type"]=>
int(3)
["timezone"]=>
string(13) "Europe/Berlin"
}
*/
Any ideas? I really need a way to check date validity.
Thank you.
Edit:
I just found why, see my answer.