4 ms·
The most annoying thing you encouter daily in PHP is the needle/haystack problem. There is no consistency with parameters of the standard library. It could be f
by allendoerfer 4y ago
The most annoying thing you encouter daily in PHP is the needle/haystack problem. There is no consistency with parameters of the standard library. It could be fixed in two ways:
a) Make everything an object, where methods can be called on:
$arr = [];
$arr->key_exists('key');
b) Create a new class-based standard library, where you call those functions statically and needle/haystack are always in the same place:
Arr::key_exists($arr, 'key');
Either way, you can deprecated all the array_..., str_..., etc. functions and end the guessing game. Other than that PHP is turning out great.
- conradfr 4y agoThis 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.
- Reubensson 4y agoI 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.
- purerandomness 4y agoIt really is irrelevant nowadays, with a) all IDEs showing you the required parameters as you type, and b) with named parameters.
- francislavoie 4y agoUserland 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.
- allendoerfer 4y agoI would like it to look pretty.
- CiPHPerCoder 4y agoThat was fixed already. https://wiki.php.net/rfc/named_params https://wiki.php.net/rfc/named_params
- allendoerfer 4y agoThat'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.
- tored 4y agoThere 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.
- Reubensson 4y ago> 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): array
- deleted 4y ago[deleted]
- jw1224 4y agoLaravel’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. [1] https://laravel.com/docs/9.x/collections https://laravel.com/docs/9.x/collections [2] https://github.com/illuminate/collections https://github.com/illuminate/collections
- user3939382 4y agoDoctrine Collections similarly solves this.
- algerd 4y agoI'm suggesting to use https://github.com/azjezz/psl https://github.com/azjezz/psl nice wrapper on php std library
- totony 4y agoalternatively, they could add calling functions with keyword arguments as in python, where you'd call key_exists(needle="needle", haystack="haystack")