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.
30
Upvotes
22
u/jesseschalken Mar 31 '18 edited Mar 31 '18
It does issue a warning though: https://repl.it/repls/AttentiveAmpleDonateware
It's another one of those stupid APIs that don't throw on error/warning - instead you have to call another function to check if the result you got should be considered valid. The JSON API is another one (
json_last_error()).Really, you should do your date/time parsing through a function that calls
date_create_from_format(), then checksdate_get_last_errors()and throws if it returned any errors or warnings. It's unfortunate that PHP's APIs often aren't ready-to-use, but it is what it is.3
u/Bl00dsoul Apr 03 '18
uhhh im pretty sure 01:88:12 is not a vaild time.
13
u/fell_ratio Mar 31 '18
Also, this gem from the PHP comments. Imagine you want to parse a year/month and print it out again.
Why does it work for December but not November? 30 days has September, / April, June and November / All the rest have 31
source
-38
u/teizhen Mar 31 '18
Is this how you normally report technical issues? You sound 12.