2

I'm trying to upgrade an app from PHP 5.4 to PHP 5.6 or 7 on Windows/IIS. Things seem to work fine for the most part, the one difference that's causing some problems when converting values is that DateTime object's string default string representation is something like 2016-03-24 14:34:22.000000 in PHP 5.6 and 7, whereas in PHP 5.4 it was 2016-03-24 14:34:22. To test, all you have to do is var_dump(new DateTime()); and you'll see the value of the "date" key.

I've searched quite a bit and am not finding anything at all in regards to this change. Is there any setting that can be used to revert the format to the way it was in 5.4?

Jon
  • 4,746
  • 2
  • 24
  • 37
Rocket04
  • 1,801
  • 5
  • 25
  • 47
  • 1
    Related: http://stackoverflow.com/q/14084222/3933332 – Rizier123 Mar 24 '16 at 18:40
  • To explain the difference that is used internally... The newer versions of PHP's `DateTime` object added functionality for microseconds. – Jon Mar 24 '16 at 18:47
  • There is this wonderful thing called [`DateTime::format()`](http://php.net/manual/en/datetime.format.php) that will let you *format* a *DateTime*. – Sammitch Mar 24 '16 at 19:01
  • @Sammitch There is this wonderful thing called not being an asshole. I'm aware of the function, but I'm dealing with an existing app and need to figure out how to best address the incompatibility. If it's definitely something that can't be addressed at a config level, I'll make the code changes necessary. – Rocket04 Mar 24 '16 at 22:03
  • @Rocket04 I don't believe there's anything you can do at a config level. The string shown shouldn't be accessible, as the linked question/answers point out, the original coder should have used `format` rather than it - but being stuck with the mess, you get to have fun changing the code. (This is as far as I know, would love to be proven wrong though ^^ ) – Jon Mar 24 '16 at 23:47
  • I guess the answer is that it can't be worked around, that's fine, I can make adjustments to get it working. @Rizier123 , I guess you were first to provide a link that pretty much answers the question, if you provide an answer I can mark it as accepted. – Rocket04 Mar 25 '16 at 12:30
  • @Jon, I think you're probably right, just needed to be sure since there are processes to make changes to the code to accommodate, so I'd avoid it if possible. But don't think it'll be a big deal. – Rocket04 Mar 25 '16 at 12:30
  • 1
    @Rocket04 If the linked Q&A answered your question? I will mark it as duplicate and you can upvote the answer which helped you. No need to write an answer if it already exists. – Rizier123 Mar 25 '16 at 12:38
  • Also I don't think @Sammitch wanted to write a mean comment here. He probably just thought that you weren't aware of the method `format()` and wanted to write this in a half way funny comment. So just take it with a bit more humor ;) Or have you ever seen a [mean 8 bit pixel sandwich](http://stackoverflow.com/users/1064767/sammitch)? – Rizier123 Mar 25 '16 at 12:40
  • @Rizier123 Thanks, I've marked that question as having the solution and upvoted the answer. As far as Sammitch, the "there is this wonderful thing" combined with the emphasis on the "format a DateTime" sure made it look like a snide remark. But whatever, won't lose sleep over it, just don't see the point of that kind of tone. – Rocket04 Mar 25 '16 at 20:23

0 Answers0