Re: Array map with reset function

From: Date: Wed, 26 Aug 2020 08:16:12 +0000
Subject: Re: Array map with reset function
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-111692@lists.php.net to get a copy of this message
On Tue, 25 Aug 2020 at 20:08, Nikita Popov <nikita.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]

« previous php.internals (#111692) next »