Re: [RFC] [Discussion] array_first() and array_last()
| From: | Rob Landers | Date: | Tue, 08 Apr 2025 16:54:11 +0000 |
| Subject: | Re: [RFC] [Discussion] array_first() and array_last() | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-127073@lists.php.net to get a copy of this message | ||
On Tue, Apr 8, 2025, at 10:53, 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’ve always viewed arrays as an infinite field of nulls. The only time this isn’t true is when
you use array_key_exists() or care about the warnings (which make it less useful, IMHO). When you
treat it as an infinite field of nulls, you get some interesting mathematical/computational
properties you can exploit. Trying to treat it as a map/indexed-array is when you start running into
weird problems.
— Rob