The following code stopped working in PHP 8:
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
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:
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.
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:
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
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:
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]
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:
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