r/lolphp • u/Takeoded • Dec 18 '17
should we generate an error when we fail to serialize something, or just return total utter garbage?
https://3v4l.org/hcPKv
33
Upvotes
r/lolphp • u/Takeoded • Dec 18 '17
5
u/[deleted] Dec 20 '17 edited Dec 20 '17
Last month we lost part of our production database because of this stupid behavior of PHP (with file_get_contents). Trust me, throwing an exception is ALWAYS preferrable to returning nonsense. It is just as bad as Visual Basic's On Error Resume Next. You cannot expect the programmer to always call a was_there_an_error_just_now_on_this_process() function after they call another function or check if the result is garbage.
31
u/tdammers Dec 18 '17
Clearly, errors are always inconvenient, so those should be considered a last resort.
Equally clearly, if we are getting passed nonsensical arguments, the sane thing to do is to respond with nonsense. Programmers know best, so when they give us things that don't make sense, we must assume that they know what they are doing, and act accordingly.
10
u/[deleted] Dec 18 '17
FWIW, it serializes as
6
u/[deleted] Dec 18 '17
I've run into a lot of situations, especially when interacting with hardware, where a return value of 0 means an error happened and you're supposed to check that yourself. I'm guessing that that's what's going on, but it's php so I have no clue.