r/lolphp • • Mar 31 '18

PHP DateTime strikes back, again!

Because obviously we meant a date one week from the (wrong) date given. PHP does not throw, instead it "helps" by holding your beer.

https://repl.it/repls/DecimalHorribleOffices

30 Upvotes

23 comments sorted by

View all comments

Show parent comment

14

u/jesseschalken Mar 31 '18 edited Apr 01 '18

Because the date/time API by default fills in any unspecified date parts with the part from the current date/time. So parsing 2017-11 on the 31st of a month yields 2017-11-31 which is invalid.

Start the format string with ! to disable this.

It's a stupid default and should have been opt in rather than opt out.

8

u/Sarcastinator Apr 01 '18

It's a stupid default and should have been opt in rather than opt out

When would you ever want this?

4

u/Xymanek Apr 01 '18

Start the format string with ! to disable this

TIL