Re: [RFC] [Discussion] array_first() and array_last()
| From: | Niels Dossche | Date: | Tue, 08 Apr 2025 22:21:57 +0000 |
| Subject: | Re: [RFC] [Discussion] array_first() and array_last() | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-127078@lists.php.net to get a copy of this message | ||
On 4/8/25 10:53 AM, Daikaras wrote:
> On 4/5/2025 6:51 PM, Niels Dossche wrote:
>> Hi internals
>>
>> I'm opening the discussion for the RFC "array_first() and array_last()".
>> https://wiki.php.net/rfc/array_first_last
>>
>> Kind regards
>> Niels
>
>
> -1 because returning
null for empty arrays is still wrong.
> Whatever similar behavior exists should be corrected to throw
> ValueError in the future. Just my 2c.
>
I think consistency is very important, hence I will stick to my reasoning why returning NULL is the
right thing at the moment.
If the behaviour of array functions on empty arrays is ever revised in the future, then we should
keep everything consistent. So e.g. if a _future_ RFC decides to make array access throw instead of
yield NULL, then this should affect array_{first,last} too IMO. However, that's not for now,
that's a lot of ifs and hypothetical future development. That discussion should happen in the
future elsewhere.