Re: [PHP-DEV] [RFC] [Discussion] array_first() and array_last()

2025-04-10 Thread Niels Dossche
On 06/04/2025 19:06, Juris Evertovskis wrote: > On 2025-04-05 18:51, Niels Dossche wrote: > Do you think it would be hard or wrong to add `array_nth`? I've had more > trouble with that as the in-place implementation is usually pretty > unreadable, e.g. > >     array_slice(array_values($array), $

Re: [PHP-DEV] [RFC] [Discussion] array_first() and array_last()

2025-04-08 Thread Niels Dossche
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 array

Re: [PHP-DEV] [RFC] [Discussion] array_first() and array_last()

2025-04-08 Thread Niels Dossche
On 4/8/25 8:46 PM, Claude Pache wrote: > Hi, > > I think that this argument is not convincing, and even counterproductive: > > * NULL is a rare legitimate value, so the potential for clashing is low > > First, it says that it is a “rare” legitimate value, which one can disagree > with. (I do di

Re: [PHP-DEV] [RFC] [Discussion] array_first() and array_last()

2025-04-08 Thread Niels Dossche
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 array

Re: [PHP-DEV] [RFC] [Discussion] array_first() and array_last()

2025-04-08 Thread Larry Garfield
On Sat, Apr 5, 2025, at 10:51 AM, 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 To add another argument: the reset() workaround doesn't work with a readonly arra

Re: [PHP-DEV] [RFC] [Discussion] array_first() and array_last()

2025-04-08 Thread Claude Pache
> Le 5 avr. 2025 à 17:51, Niels Dossche a écrit : > > 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 Hi, I think that this argument is not convincing, and even counterproductive:

Re: [PHP-DEV] [RFC] [Discussion] array_first() and array_last()

2025-04-08 Thread Andreas Hennings
On Tue, 8 Apr 2025 at 18:38, Levi Morrison wrote: > > On Sat, Apr 5, 2025 at 9:51 AM 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 > > I dislik

Re: [PHP-DEV] [RFC] [Discussion] array_first() and array_last()

2025-04-08 Thread Andreas Hennings
On Mon, 7 Apr 2025 at 02:48, Ayesh Karunaratne wrote: > > > On Mon, Apr 7, 2025 at 2:05 AM Bilge wrote: > > ... [snip] I suggest first proving there is a > > legitimate need. > > I did a quick GitHub search for a common pattern of accessing an array > value by using the `array_key_first` and `arr

Re: [PHP-DEV] [RFC] [Discussion] array_first() and array_last()

2025-04-08 Thread Rob Landers
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 `n

Re: [PHP-DEV] [RFC] [Discussion] array_first() and array_last()

2025-04-08 Thread Levi Morrison
On Sat, Apr 5, 2025 at 9:51 AM 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 I dislike all the functions where `null` is a valid value, which can also be confu

Re: [PHP-DEV] [RFC] [Discussion] array_first() and array_last()

2025-04-08 Thread Daikaras
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 b

Re: [PHP-DEV] [RFC] [Discussion] array_first() and array_last()

2025-04-06 Thread Bilge
On 07/04/2025 01:47, Ayesh Karunaratne wrote: On Mon, Apr 7, 2025 at 2:05 AM Bilge wrote: ... [snip] I suggest first proving there is a legitimate need. I did a quick GitHub search for a common pattern of accessing an array value by using the `array_key_first` and `array_key_last` functions: `

Re: [PHP-DEV] [RFC] [Discussion] array_first() and array_last()

2025-04-06 Thread Larry Garfield
On Sun, Apr 6, 2025, at 7:47 PM, Ayesh Karunaratne wrote: >> On Mon, Apr 7, 2025 at 2:05 AM Bilge wrote: >> ... [snip] I suggest first proving there is a >> legitimate need. > > I did a quick GitHub search for a common pattern of accessing an array > value by using the `array_key_first` and `array

Re: [PHP-DEV] [RFC] [Discussion] array_first() and array_last()

2025-04-06 Thread Ayesh Karunaratne
> On Mon, Apr 7, 2025 at 2:05 AM Bilge wrote: > ... [snip] I suggest first proving there is a > legitimate need. I did a quick GitHub search for a common pattern of accessing an array value by using the `array_key_first` and `array_key_last` functions: ```php $value = $arr[array_key_first($resul

Re: [PHP-DEV] [RFC] [Discussion] array_first() and array_last()

2025-04-06 Thread Bilge
On 06/04/2025 18:06, Juris Evertovskis wrote: I also suspect that an in-engine implementation might have more performance gains compared to an userland one. That applies to literally anything, obviously; one less layer of abstraction is always more efficient. That's therefore not a reason to

Re: [PHP-DEV] [RFC] [Discussion] array_first() and array_last()

2025-04-06 Thread Juris Evertovskis
On 2025-04-05 18:51, 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 Hi, Do you think it would be hard or wrong to add `array_nth`? I've had more trouble with that as th

Re: [PHP-DEV] [RFC] [Discussion] array_first() and array_last()

2025-04-05 Thread Niels Dossche
On 05/04/2025 20:00, Claude Pache wrote: > Hi Niels, > > It is reasonable. I have a userland implementation of that in my codebase > since long ago. > > You missed the following point when discussing the behaviour for empty array: > > * Consistent with `array_shift()` and `array_pop()`, which a

Re: [PHP-DEV] [RFC] [Discussion] array_first() and array_last()

2025-04-05 Thread Claude Pache
> Le 5 avr. 2025 à 17:51, Niels Dossche a écrit : > > 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 Hi Niels, It is reasonable. I have a userland implementation of that in my c