Laravel’s “Collections” library [1] solves this, and is a breath of fresh air. Easily one of the best features of the framework (though you can also use it as a separate package, outside of a Laravel app [2]).
It’s simple to use, but extremely powerful. I pretty much always use Collections over native array functions these days.
Re:Whats New in PHP 8.2
by user3939382 on Monday April 25, 2022 @12:33PM
(#31157220)
Doctrine Collections similarly solves this.
This is so funny to me how it's constantly brought up here but has never been an inconvenience to me, and I started with PHP3 in 1998.
Even before auto-completion I guess I would just read the docs.
To each his own I guess.
Re:Whats New in PHP 8.2
by Reubensson on Monday April 25, 2022 @05:06PM
(#31160601)
I am sure that if you use a language/library for long enough, its bad design descisions aren't a huge problem to you.
Reading the docs of course helps, but it is still inconvenience and waste of time to check inconsistent parameter order and function naming from docs. I don't understand why people are so keen on defending these things.
Re:Whats New in PHP 8.2
by purerandomness on Monday April 25, 2022 @07:16PM
(#31162089)
It really is irrelevant nowadays, with a) all IDEs showing you the required parameters as you type, and b) with named parameters.
Re:Whats New in PHP 8.2
by CiPHPerCoder on Monday April 25, 2022 @11:24AM
(#31156164)
That was fixed already.
Re:Whats New in PHP 8.2
by allendoerfer on Monday April 25, 2022 @11:57AM
(#31156697)
That's a good addition but not really a fix. A fix would be to have a consistent ordering of parameters and a conceptually consistent interface.
I'm suggesting to use https://github.com/azjezz/psl
nice wrapper on php std library
There is actually some consistency, array functions have the same parameter order and string functions have theirs, it just different order between these two groups of functions.
Re:Whats New in PHP 8.2
by Reubensson on Monday April 25, 2022 @11:51AM
(#31156600)
> array functions have the same parameter order and string functions have theirs
Except when they have different order :)
array_filter(array $array, ?callable $callback = null, int $mode = 0): array
array_map(?callable $callback, array $array, array ...$arrays): arrayalternatively, they could add calling functions with keyword arguments as in python, where you'd call key_exists(needle="needle", haystack="haystack")
Re:Whats New in PHP 8.2
by francislavoie on Monday April 25, 2022 @11:22AM
(#31156137)
Userland frameworks/libs provide those kinds of helper classes already.
And IDEs completely solve the problem of knowing parameter orders by hinting them as you type the functions.
This really isn't that big of a deal.
Re:Whats New in PHP 8.2
by allendoerfer on Monday April 25, 2022 @11:51AM
(#31156586)
I would like it to look pretty.
a) Make everything an object, where methods can be called on:
b) Create a new class-based standard library, where you call those functions statically and needle/haystack are always in the same place: Either way, you can deprecated all the array_..., str_..., etc. functions and end the guessing game. Other than that PHP is turning out great.