3 ms·
I don’t see how a string “null” would break anything besides a very stupidly written program (e.g., one which tries to eval() the input) or an ordinary program
by throwaway894345 6y ago
I don’t see how a string “null” would break anything besides a very stupidly written program (e.g., one which tries to eval() the input) or an ordinary program written in a very stupid language (e.g., one which tries to coerce strings to other types—PHP, is that you?).
I’m a big fan of pattern matching (especially statically verified pattern matching so sorry elixir), but I don’t see how it would help here.
- rgj 6y agoEven PHP finds null==“null” to be false.
- hunter2_ 6y agoAnd at least you get to strongly compare by adding an extra = (e.g., ===, !==). I just wish the extra character (i.e., the not-as-default versions) weakened instead, like a tilde. But yes, all strings are truthy. Except an empty string! And maybe some little-used nullish characters? Doubtful, but...
- zerocrates 6y ago> But yes, all strings are truthy. Except an empty string! And maybe some little-used nullish characters? Doubtful, but... Or "0"
- timw4mail 6y agoBut not in PHP 8
- zerocrates 6y agoThey changed a lot of the weirder string conversion stuff in PHP 8, but I'm pretty sure "0" is still falsy.
- hunter2_ 6y agohttp://sandbox.onlinephpfunctions.com/code/d6df91536669985a6502c2aeb2362722005e608d http://sandbox.onlinephpfunctions.com/code/d6df91536669985a6... Set it to PHP 8 and click "Execute code," then set it to PHP 7 and Execute again. They give the same result, which is that "0" is falsy in both versions.
- 3pt14159 6y agoBecause there was this period of time where the prevailing wisdom was "be liberal in what you accept, and conservative in what you emit" to enable computer systems to handle a wider array of cases. Some people still adhere to it. I don't. If I want to extend a system that's currently in English to also accept Arabic or Farsi / Persian, you better believe I'm sanitizing that input carefully. Otherwise I'm opening up my application to zero width non-joiners[0] and all sorts of random fingerprinting for my English speaking users. I know it's a pain, but I'd rather just do it right. [0] https://www.zachaysan.com/zero https://www.zachaysan.com/zero
- _0ffh 6y agoYes, implicit type casting is the work of the devil. Even the limited case in C is a popular source of trouble, never mind implicitly casting between strings and other types. Similar case with SQL's "NULL".