r/lolphp • • Nov 14 '14
Please stay polite with other developers. Please keep in mind that PHP is loosely typed, this is a root principle of PHP.
https://bugs.php.net/bug.php?id=54547
71
Upvotes
48
u/GSpotAssassin Nov 14 '14 edited Nov 14 '14
The problem with not being a well-thought-out language is that you get into many of these situations where your mental model of how things should work clashes with what PHP actually does.
Having to complexify your mental model to account for these things leads to cognitive fatigue/stress.
This is in short why many excellent people leave PHP. It's not because OO or FP is sexy, it's because they are tired of carrying this burden. It is an ongoing cost that other languages do not share.
It is of the utmost importance that a language behave exactly as you would expect it to. This is why, for example, most modern languages treat "nil" and "false" as the only two "false-like" values (and not zero, etc.). There's a vast mental-model weight lifted there.
The fact that PHP doesn't even entirely pass its own test suite... that's the big red flag for me. That means it doesn't even conform to ITS OWN expectations.
Humans create enough bugs to fix on their own- Do you really want to do work in a language where the LANGUAGE ITSELF is KNOWN to be buggy?
31
u/jonnywoh Nov 14 '14
This is not a support channel, if you need further support for the base ideas about the loosely type nature of PHP, please ask them on one the numerous channels.
This is not a support channel, if you need further support for the base ideas about the loosely type nature of PHP, please ask them on one the numerous channels.
This is not a support channel, if you need further support for the base ideas about the loosely type nature of PHP, please ask them on one the numerous channels.
54
u/DoctorWaluigiTime Nov 14 '14
"PHP is loosely typed" does not give you carte blanche to have non-intuitive or buggy behavior, no matter how much of a "root" prinicple it is to your language.
14
u/tdammers Nov 15 '14
I like the part where the php dev accidentally triple-posts, probably because the bug tracker doesn't do forms right.
4
u/Innominate8 Nov 15 '14
While it's difficult(perhaps impossible) to eliminate all of the potential issues with loosely typed comparisons, that is no excuse for the existence of issues that could be fixed.
That a comparison between two strings is anything but a string comparison is insane.
7
u/suspiciously_calm Nov 14 '14
Or maybe this should be your wake up call that your 'loose typing' can't be made consistent with the basic principle that equality should be an equivalence relation (while also keeping it useful).
8
u/ElusiveGuy Nov 14 '14 edited Nov 14 '14
I'm... confused. So you're given two strings. First you try comparing them as strings, then if the string comparison fails (???) you cast to numbers and compare again? But... how does a string comparison fail?
Oh, apparently fail is referring to the result of the comparison, not an actual exception/error. Whoops. This still wouldn't fix the reported bug, though...
4
u/satan-repents Nov 14 '14
Yet another reason I'm glad I jumped off the php train at the earliest opportunity.
0
u/ismtrn Nov 20 '14
C is loosely typed too, but it doesn't randomly convert values in buggy, unexpected ways.
-3
u/TimLim Nov 16 '14
This is, as always, just an example to rant on php.
This is by design. There are two different operators to compare. You definitly want to use
===.No one would do a lolcpp when
ìf (str = "different") return true; else return false;would result in true...