Array map with reset function

  111684
August 25, 2020 17:47 vorismi3@fel.cvut.cz (=?UTF-8?Q?Michael_Vo=C5=99=C3=AD=C5=A1ek_-_=C4=8CVUT_FEL?=)
The following code stopped working in PHP 8: 

https://3v4l.org/UlIE3 

is it a bug or a feature? 

is posting issues like this to internals@lists.php.net email prefered
over opening bug directly? or is there any special email for it? 

With kind regards / Mit freundlichen Grüßen / S přátelským pozdravem,

Michael Voříšek
  111685
August 25, 2020 18:52 internals@lists.php.net ("Levi Morrison via internals")
On Tue, Aug 25, 2020 at 11:47 AM Michael Voříšek - ČVUT FEL
<vorismi3@fel.cvut.cz> wrote:
> > The following code stopped working in PHP 8: > > https://3v4l.org/UlIE3 > > is it a bug or a feature? > > is posting issues like this to internals@lists.php.net email prefered > over opening bug directly? or is there any special email for it? > > With kind regards / Mit freundlichen Grüßen / S přátelským pozdravem, > > Michael Voříšek
The documentation for array_map doesn't mention references at all. I'm inclined to believe it to be an intentional warning, but it may be a regression. I recommend using array_walk, as it _does_ mention reference support.
  111686
August 25, 2020 19:08 nikita.ppv@gmail.com (Nikita Popov)
On Tue, Aug 25, 2020 at 7:47 PM Michael Voříšek - ČVUT FEL <
vorismi3@fel.cvut.cz> wrote:

> The following code stopped working in PHP 8: > > https://3v4l.org/UlIE3 > > is it a bug or a feature? >
This is an intentional change, if that's what you're asking. array_map() is not spec'd to pass by reference, so it doesn't. is posting issues like this to internals@lists.php.net email prefered
> over opening bug directly? or is there any special email for it? >
Please prefer reporting issues at bugs.php.net over this mailing list. (At least for bugs -- for non-trivial feature requests, the mailing list may be better.) Regards, Nikita
  111692
August 26, 2020 08:16 rowan.collins@gmail.com (Rowan Tommins)
On Tue, 25 Aug 2020 at 20:08, Nikita Popov ppv@gmail.com> wrote:

> On Tue, Aug 25, 2020 at 7:47 PM Michael Voříšek - ČVUT FEL < > vorismi3@fel.cvut.cz> wrote: > > > The following code stopped working in PHP 8: > > > > https://3v4l.org/UlIE3
To be pedantic: it didn't stop working, it just started raising Warnings. The return value of array_map remains the same.
> > > > > is it a bug or a feature? > > > > This is an intentional change, if that's what you're asking. array_map() is > not spec'd to pass by reference, so it doesn't. >
As with many uses of reset(), this one doesn't really need to be by reference, it's being used for its output. Unfortunately, array_value_first failed at RFC [https://wiki.php.net/rfc/array_key_first_last#vote], so I presume the recommended replacement code in the general case is this: array_map(fn($x)=>$x[array_key_first($x)], $rows) Of course for a list-style array like the example shown, it can be a lot simpler: array_map(fn($x)=>$x[0], $rows) Regards, -- Rowan Tommins [IMSoP]
  111700
August 27, 2020 10:14 drealecs@gmail.com (=?UTF-8?Q?Alexandru_P=C4=83tr=C4=83nescu?=)
On Wed, Aug 26, 2020 at 11:16 AM Rowan Tommins collins@gmail.com> wrote:
> > On Tue, 25 Aug 2020 at 20:08, Nikita Popov ppv@gmail.com> wrote: > > > On Tue, Aug 25, 2020 at 7:47 PM Michael Voříšek - ČVUT FEL < > > vorismi3@fel.cvut.cz> wrote: > > > > > The following code stopped working in PHP 8: > > > > > > https://3v4l.org/UlIE3 > > > > To be pedantic: it didn't stop working, it just started raising Warnings. > The return value of array_map remains the same. > > > > > > > > > > > is it a bug or a feature? > > > > > > > This is an intentional change, if that's what you're asking. array_map() is > > not spec'd to pass by reference, so it doesn't. > > > > > As with many uses of reset(), this one doesn't really need to be by > reference, it's being used for its output. Unfortunately, array_value_first > failed at RFC [https://wiki.php.net/rfc/array_key_first_last#vote], so I > presume the recommended replacement code in the general case is this: > > array_map(fn($x)=>$x[array_key_first($x)], $rows) > > Of course for a list-style array like the example shown, it can be a lot > simpler: > > array_map(fn($x)=>$x[0], $rows) > > Regards, > -- > Rowan Tommins > [IMSoP]
array_map(fn($x)=>reset($x), $rows) would work as well Alex