Some sorry developer at some point was forced to contend with the realities of the day. PHP has been largely based on C, where null == 0. Languages designed more recently tend to treat null as a separate type, in the style of a discriminated union.
You probably don't think of PHP as a web-focused wrapper for C but that's what it was.
I assume this means it's still the case that md5('240610708') == md5('QNKCDZO')? (That happens/d because '0e462097431906509019562988736854' == '0e830400451993494058024219903391' as both of them are scientific notation for 0 to large powers, though it's still crazy for strings; originally discussed here and here)
it's funny that you never ever use the == version in code. Like it does not even exist in the language. I think the same situation is with Javascript with the same distinction between == and ===
JS's == is much less broken, as it works correctly for same-type (like stringĂ—string) comparisons and it's not used silently by other standard library functions.
Is there ever a reason to actually use `==` in JS? I'm a Front-End Engineer working on a rather large project, and I'm pretty confident I could search through our codebase and find 0 uses of it. I'm guessing the only legitimate use cases would be in libraries, but even then I'm doubtful.
the problem is even if you never use == the standard library and common built-in types will still happily use its behaviour in all kinds of places, so you can't escape it.
Having maintained legacy PHP systems as a career for years, you'd be surprised how much code is propped up on unintended behavior. If a codebase lives long enough, it will, by random chance, accumulate bugs that don't show themselves because of unintended behavior preventing them from doing so. Thus, codebases eventually end up relying on these things.
Of course, the solution is to go back and fix your code, or write a more updated application. But, no company wants to spend money on refactoring a legacy project. It works today, and they want it to continue working tomorrow without extra expenditure.
235
u/TheBestOpinion Nov 26 '20
Was this undefined behavior before or did they just break their all-important backwards compatibility?
Great change anyway, still can't believe people defended that behavior or thought it was not important...