php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #80699 array_map no longer passes by reference
Submitted: 2021-02-02 19:24 UTC Modified: 2021-02-02 19:45 UTC
Votes:5
Avg. Score:4.4 ± 0.8
Reproduced:5 of 5 (100.0%)
Same Version:2 (40.0%)
Same OS:3 (60.0%)
From: donatj at gmail dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 8.0.1 OS: All
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: donatj at gmail dot com
New email:
PHP Version: OS:

 

 [2021-02-02 19:24 UTC] donatj at gmail dot com
Description:
------------
array_map no longer passes by-reference.

This has broken a lot of things for us.

This very well may be an intentional change, but I didn't see it noted, and if it is, it should be documented on the array_map page as a change?

Test script:
---------------
<?php

// https://3v4l.org/BdWq7

$data = array(
    array(1,2,3),
    array(4,5,6),
);

$data = array_map('reset', $data);

print_r($data);

Expected result:
----------------
Array
(
    [0] => 1
    [1] => 4
)


Actual result:
--------------
Warning: reset(): Argument #1 ($array) must be passed by reference, value given in /in/BdWq7 on line 8

Warning: reset(): Argument #1 ($array) must be passed by reference, value given in /in/BdWq7 on line 8
Array
(
    [0] => 1
    [1] => 4
)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-02-02 19:45 UTC] bwoebi@php.net
-Type: Bug +Type: Documentation Problem
 [2021-02-02 19:45 UTC] bwoebi@php.net
Yes, that's an intentional change; if you need a reference, there is array_walk for that.
 [2021-12-31 18:21 UTC] git@php.net
Automatic comment on behalf of cmb69
Revision: https://github.com/php/doc-en/commit/31cacb6f262f455c616094cfe6d09bc0d1df2748
Log: Fix #80699: array_map no longer passes by reference
 [2021-12-31 18:21 UTC] git@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 17:01:34 2025 UTC