Hacker News new | past | comments | ask | show | jobs | submit
After over two decades of working in PHP, I'm now working in Java. PHP is basically Java-lite. I am absolutely loving the compile-time safety of Java, but I dearly miss PHP's maps and arrays. In Java, the amount of verbosity for defining a map/list and operating on it is overwhelming.

Modern PHP is great. Many powerful language features, excellent performance, great community and package ecosystem, and decent enough safety with modern static analysis tools.

I'm not too sure I agree with the author's complaints here. When using something like array_filter, you're typically mapping from collection to collection (i.e. you don't care about the first element--you care about the whole thing) and so this problem is really a non-issue. The next follow up step would usually be foreach, or another operation like array_map, in which case it's a non-issue.

If you really do need the first element, you can use array_first. And if you really do need a fixed-sized collection, you can use SplFixedArray.

The point on properties is valid to an extent, but IMO not really an issue you commonly run into in the real world (regardless of language, your constructors should generally return an object in a usable state).

loading story #48249042
loading story #48249874
loading story #48248917
loading story #48250069
loading story #48249440
loading story #48249267
To note, it is surprisingly refreshing to completely forgo instanciable classes on a modern codebase.

Phpstan deals well with type definitions, arrays are powerful enough to contain whatever needed, and functions can be stored and passed around easily enough.

loading story #48248975
I ended up writing a simple collection class with in-memory indexing twice already in two different monoliths. Maybe I should make an extension.....
Every time I work in another language I miss PHP’s arrays.
loading story #48248873
loading story #48248750
loading story #48248840
if("0") {} being equivalent to if(false) {} still gives me nightmares even though I've stopped using PHP for at least 6 years now :)
loading story #48248894
loading story #48248844
loading story #48248957
loading story #48249498
loading story #48248943
I think the “bad rep” is coming from developers that stopped developing themselves.
loading story #48249612