Re: Re:[VOTE] array_key_first(), array_key_last(), array_value_first(),array_value_last()
| From: | Dan Ackroyd | Date: | Tue, 10 Jul 2018 14:46:12 +0000 |
| Subject: | Re: Re:[VOTE] array_key_first(), array_key_last(), array_value_first(),array_value_last() | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-102717@lists.php.net to get a copy of this message | ||
Also voting no, and wished I had mailed earlier.
Accessing the keys and values separately is not a good design in my
opinion, as it leads to:
> All four functions either return the requested key/value
> or null if an empty array is provided.
Having what looks likes valid values returned for array_value_first()
and array_value_last()
A think a better pattern would be to return a tuple as Levi suggested.
[$key, $value] = array_first($array);
[$key, $value] = array_last($array);
For people not used to returning tuples.....you should branch out a
bit and try using them.
They are a better pattern to use when returning multiple values from
a function that don't need/deserve their own class/struct creating.
cheers
Dan
Ack
On 9 July 2018 at 18:31, CHU Zhaowei <me@jhdxr.com> wrote:
> I voted no.
> I don't think we have an agreement on dealing with non-existing value, and the way this
> RFC proposed, just returning null without any notice/warning, is wrong IMO. I know we already do
> this in other array_* functions, but we cannot keep making mistakes just because we already made
> same mistake.
>
> Regards,
> CHU Zhaowei