5 ms·
What's the equivalent of === for < and > in PHP?
by vesak 8y ago
What's the equivalent of === for < and > in PHP?
- chx 8y agoUse < and > for numbers and strcmp for strings. A strict type > would be very weird because besides returning TRUE and FALSE it'd need to throw a TypeError, I guess?
- vesak 8y ago>A strict type > would be very weird because besides returning TRUE and FALSE it'd need to throw a TypeError, I guess? Yes, which would make it behave exactly like probably every language with strong runtime typechecks. Very weird indeed. It's obviously much more preferable that the code sometimes does the wrong thing without warning. And of course with static typing, it would be extremely weird since the code wouldn't even pass the compiler!
- dpcx 8y agoI don't think the snark in this response is super helpful; a simple "Yes, throw a TypeError when the types are incorrect" would have sufficed.