> I completely understand what you're saying and I don't disagree with the 
> thought process. What I disagree with is your statement that you will always 
> use array_first() together with array_key_first(). When talking about 
> standard lists (indexed from 0 to upper-bound), array_first() is an order of 
> magnitude more useful than array_key_first() as we always know what the first 
> key is: 0.

This is simply not true, 0 is not always the first key in a list,
especially after filtering it. Hence there is a need for this function
in the first place.

> Here's another thought process: suppose PHP never gets array_first(). In your 
> Fiber scenarios, you need to use `array_key_first()` and 
> `$array[array_key_first()]` and deal with any edge cases around this. You 
> have found issues, dealt with it and you're now aware of them. It's really 
> nice that you want to avoid others from going through the same pain as you 
> did, but the fact is `array_first()` or `$array[0]` is not only ALWAYS used 
> together with needing to know the key or not ALWAYS used with Fibers.

PHP chose to implement Fibers in this way and it should be cognizant
of them when implementing new features. That's all I'm saying. Whether
anyone who matters, actually cares, is another story. All I can do is
say something. You can only lead a horse to water, after all, you
can't force it to drink.

> What I'm saying is: don't force a design functionality only for your use 
> case, especially as basic and fundamental as PHP Arrays. I don't want to be 
> forced to write `[$value, $_] = array_first()` just because there's a corner 
> of PHP functionality that needs special treatment. If this was 
> fibers_array_first() I wouldn't mind at all.

If we went with the array return scenario:

// assuming it is in [value, key] form
[$value] = array_first($arr);
[,$key] = array_first($arr);
[$value, $key] = array_first($arr);

Or with the approach I suggested:
$value = array_first($arr);
array_first($arr, $key);
$value = array_first($arr, $key);

I don't think this is asking for much, nor complicated. Both
approaches seem simpler and less verbose than:

[$value, $key] = [array_first($arr), array_key_first($arr)];

At the end of the day, I'll be happy with any solution implemented,
because it is still far better than what we have currently.

Robert Landers
Software Engineer
Utrecht NL

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to