Re: [PHP-DEV] array_reduce callback key

2024-07-17 Thread Larry Garfield
On Wed, Jul 17, 2024, at 9:01 AM, Bilge wrote: > On 17/07/2024 01:41, Levi Morrison wrote: >> Adding arguments to a function can mess up internal callbacks, btw, so I >> don't like modifying the >> existing function. > Which internal callbacks can be messed up by this change? They clearly > aren'

Re: [PHP-DEV] array_reduce callback key

2024-07-17 Thread Bilge
On 17/07/2024 01:41, Levi Morrison wrote: Adding arguments to a function can mess up internal callbacks, btw, so I don't like modifying the existing function. Which internal callbacks can be messed up by this change? They clearly aren't tested, as the build is passing. Cheers, Bilge

Re: [PHP-DEV] array_reduce callback key

2024-07-17 Thread Lily Bergonzat
It would make sense for it to be the last argument. My first thought was also that PHP doesn't usually care if you add extra arguments, but "internal callbacks" made me think they were C callbacks, and in that case I don't really know. On Wed, Jul 17, 2024 at 10:08 AM Rob Landers wrote: > > On We

Re: [PHP-DEV] array_reduce callback key

2024-07-17 Thread Rob Landers
On Wed, Jul 17, 2024, at 09:55, Lily Bergonzat wrote: > While it *is* indeed a workaround, you can very easily > access the values of the array from the keys, since that > literally is what the keys are for. > > While I also think it's weird that not all php array functions > with callbacks do pas

Re: [PHP-DEV] array_reduce callback key

2024-07-17 Thread Lily Bergonzat
While it *is* indeed a workaround, you can very easily access the values of the array from the keys, since that literally is what the keys are for. While I also think it's weird that not all php array functions with callbacks do pass the key as an argument, and while I also stumbled upon that prob

Re: [PHP-DEV] array_reduce callback key

2024-07-16 Thread Levi Morrison
On Tue, Jul 16, 2024 at 5:17 PM Bilge wrote: > > Hi Internals, > > I just ran into a case where I needed the array key in an array_reduce() > callback, but I can't access it :( > > So I wrote a PR to fix it: https://github.com/php/php-src/pull/14986 > > What do you think? Does this need an RFC? >

Re: [PHP-DEV] array_reduce callback key

2024-07-16 Thread Bilge
On Wed, 17 Jul 2024, 01:29 mickmackusa, wrote: > It is untrue that you "can't access it"; you just need to use an array of > keys as the input array. > >> It is absolutely true and your workaround is just that; a workaround that doesn't work at all when you also need the value. Cheers, Bilge

Re: [PHP-DEV] array_reduce callback key

2024-07-16 Thread mickmackusa
This is not the first time that a developer needs access to the input array's keys within the callback of array_reduce(). It is untrue that you "can't access it"; you just need to use an array of keys as the input array. Some frameworks already have the feature of key access built into their metho

[PHP-DEV] array_reduce callback key

2024-07-16 Thread Bilge
Hi Internals, I just ran into a case where I needed the array key in an array_reduce() callback, but I can't access it :( So I wrote a PR to fix it: https://github.com/php/php-src/pull/14986 What do you think? Does this need an RFC? Cheers, Bilge