43 ms·
This makes me so glad I don't use PHP.
by sebzim4500 4y ago
This makes me so glad I don't use PHP.
- thunderbong 4y agoEvery language has it's quirks.
- Izkata 4y agoAnd this one had a purpose. Remember, PHP was designed (as much as it was "designed") for less-technical people. And everything comes through $_GET and $_POST as strings. The way I see it, this was a crude attempt to make things like $_GET['age'] > 18 work without having to remember to convert types manually. Javascript was the same with input.value The == conversions become more intuitive if you keep this use case in mind and think about semantic equality instead of programming's more traditional exact equality.
- giantrobot 4y agoThat's not a quirk. That's a fundamentally broken design. It flagrantly violates the principal of least surprise. The language is almost helping people write bugs in their code.
- dale_glass 4y agoIt's the kind of thing you get with weak typing. Perl does better here by requiring "eq" for strings, so there's less chance for such an issue to happen. But you have the "zero but true" fun quirk -- "0e0" evaluates to 0 numerically, but 1 logically because it's not an empty string.
- eknkc 4y agoYeah but there are levels of weak typing. JS does not do this as both operands are strings, it compares them as strings. That makes tons of more sense compared to this. Not that JS is the most sane language out there but PHP tends to make it a lot easier to shoot yourself.
- tuyiown 4y agoThe casting occurs for both operands that have same type, in narrower type space, with non trivial rules, behind your back, is really acid level of a surprise. The kind that would make the removal of the "==" operator reasonable.
- VHRanger 4y agoPython does weak typing and doesn't have 1% of the unexpected nonsense PHP has.
- mkl 4y agoYou're probably thinking of dynamic typing, which Python has, but Python's typing is strong, not weak, so e.g. '1' == 1 returns False.
- zarzavat 4y agoPython has strong typing, but it does use duck typing. Weak typing is when a language inserts implicit coercions in unexpected places, such as 42 == “42”. It’s not a precisely defined term. Another example is in C where pointers and values may be mixed and matched, although less so nowadays.
- giantrobot 4y agoPython has dynamic but strong typing. There's no hidden type coercion. A dev might run into behavior they don't expect but the behavior is documented and regular.
- vhcr 4y agoPython is strongly typed though.
- moring 4y agoThat only means you have to distinguish by frequency and magnitude of quirks, and languages are very different then.
- ahofmann 4y agoThis is great news! Everyone who doesn't use PHP increases my hourly rate ;-)
- skrowl 4y ago[dead]
- omnibrain 4y agoYou are going to love https://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/ https://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/