Hacker News new | past | comments | ask | show | jobs | submit login

Does it? If you declare strict, use strict comparison operators and typehint your arguments and returns, what more care do you need? These are not particularly onerous, the strict declaration is trivially templateable in any editor as it's the first line, you'd write types in any language and getting used to only use === !== and forget == and != is ... easy?



There is an absolutely phenomenal static analyser for PHP called enhanced inspections EA (free version and commercial very) that will flag == when === should be more appropriate (among many other things).

For people not using Intellij (or wanting a tool that can be used as part of commit/deploy setup there is phan which is well executed).

I've mocked PHP for a long time (been using it for various day jobs for over a decade) but they've made massive strides in the last 2-3 years to the extent where used properly it's approach 'not a bad' language status.


Type declarations definitely help a lot, but:

* touching basically any standard library function negates a lot of the benefit

* silent coercion still happens everywhere inside a function body

Even if strict comparison, you have to spend a lot of code validating the input and it's really easy to forget an edge case.


> what more care do you need?

1. Generic typehints, for one. Typehinting half the methods as returning a generic `array` is not fun.

2. And that's before you even remember that PHP's array is both a vector and a hashmap, so you need to install a PECL extension or a third-party library to get proper Map/Sequence/etc.


What's the equivalent of === for < and > in PHP?


Use < 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?


>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!


I 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.


Congratulations for being the last straw. I'm getting out of this site for good.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: