4 ms·
I've been using PHP semi-regularly since the late 90s. It's been empowering and infuriating. The ecosystem is radically better than it used to be. Composer and
by joemaller1 7y ago
I've been using PHP semi-regularly since the late 90s. It's been empowering and infuriating.
The ecosystem is radically better than it used to be. Composer and the Packagist registry are as mature and dependable as npm, PyPI or RubyGems. (despite hours lost to my own namespace screwups). I'm also happy to see the Prettier-PHP project automating and enforcing code-style standards.
For whatever reason, I often feel clumsier after working on a PHP project. After working in other languages like JS or Python, I tend to feel like I've leveled-up my skills.
One thing I wish PHP would address is the inconsistency in its map-filter-reduce functions -- their argument-order doesn't match (array, callback) vs. (callback, array):
array_filter($arr, $fn)
array_map($fn, $arr)
array_reduce($arr, $fn)
The amount of cognitive overhead I've wasted on those is ridiculous.
- https://packagist.org/ https://packagist.org/
- https://github.com/prettier/plugin-php https://github.com/prettier/plugin-php
- taytus 7y agoInfuriating? I'm not here to defend php but even when I do agree that inconsistencies are not nice, nothing stop you of creating your own wrapper for these functions. Infuriating? really?
- jonatron 7y agoBack when I wrote PHP, the solution was to use an editor which shows you functions arguments after you type the open bracket.
- earthboundkid 7y agoYes, it is really infuriating that PHP literally cannot commit to any coding standards whatsoever for its standard library. Even if you choose to write your own wrappers, it doesn't change other people's code which you have to read. It's idiotic that the developers of PHP didn't take 5 seconds to consult their other functions before adding new ones with the arguments reversed, and it is totally appropriate to feel angry at them for their unconscionable shortsightedness.
- eithed 7y agoLaravel has Collection class that wraps arrays - as such you can do `(new Collection([your array]))->filter(function(){})` or `(new Collection([your array]))->map(function(){})`. It also adds other helper methods. I guess Symfony has something similar Reference: https://laravel.com/docs/5.8/collections https://laravel.com/docs/5.8/collections
- Kiro 7y agoOr collect([your array]). I love Laravel collections.
- benp84 7y agoI hear this complaint a lot but I find those argument orders completely intuitive. You filter (1) an array with (2) a function. You map (1) a function over (2) an array. You reduce (1) an array with (2) a function. It follows exactly what I'm thinking when I type it. To reverse the orders would be, what? "Mapping an array with a function?" "Filter a function on an array?"
- momokoko 7y agoFrom a performance perspective, you likely want to do those with `foreach` anyway in PHP. Especially when the array function is fed a closure. I know it is not as interesting as using those functions, but because of PHP internals, `foreach` is almost always preferred. https://stackoverflow.com/questions/18144782/performance-of-foreach-array-map-with-lambda-and-array-map-with-static-function https://stackoverflow.com/questions/18144782/performance-of-...