On Wed, Aug 26, 2020 at 11:16 AM Rowan Tommins <rowan.coll...@gmail.com> wrote: > > On Tue, 25 Aug 2020 at 20:08, Nikita Popov <nikita....@gmail.com> wrote: > > > On Tue, Aug 25, 2020 at 7:47 PM Michael Voříšek - ČVUT FEL < > > voris...@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 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php