I’m working on a PHP script for WordPress and I’m making an API call to our system and it includes a .Net to Json formatted DateTime string. Using regular expressions I have stripped it down to the seconds since the Unix Epoch. As I understand, I should be able to then create a DateTime object from that using DateTime::createFromFormat(‘U’, $time); but the script ceases its execution when it encounters it (it executes everything up to that point). I wrapped it in a try/catch but even that’s not being executed, it just simply ‘dies’, I guess.
What’s going on here?
preg_match_all('/\d+/', $post->discussion->posttime, &$ms);
$ms = $ms[0];
var_dump($ms[0]);
$time = substr($ms[0], 0, strlen($ms[0]) - 3);
var_dump($time);
$date = DateTime::createFromFormat('U', $time);
//Nothing after the above line is executed
var_dump($date);
...
Output to the page looks like:
string(13) "1332244919776"
string(10) "1332244919"
Nothing I put after the DateTime line is displayed (or as far as I can tell, executed). I’ve used valid Unix Timestamps from online and it still doesn’t work. I’ve tried other formats as well (‘Y-m-d’) with matching date string formats and none of them have worked. Creating a regular ‘now’ DateTime object using new DateTime(); works though.
That sounds like a fatal error with error reporting off.
The most likely cause of the problem is that you are using a version of php < 5.3. Support for
createFromFormatwas added in version 5.3 while theDateTimeobject was added in version 5.2.