php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71660 array_column behaves incorrectly after foreach by reference
Submitted: 2016-02-25 00:12 UTC Modified: -
From: icarpenter at leadid dot com Assigned:
Status: Closed Package: Arrays related
PHP Version: 7.0.3 OS:
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: icarpenter at leadid dot com
New email:
PHP Version: OS:

 

 [2016-02-25 00:12 UTC] icarpenter at leadid dot com
Description:
------------
If you do a foreach by reference on an array, array_column will ignore the third parameter

Test script:
---------------
<?php
$arr = array('id' => 12345, 'name' => 'sam');
foreach ($arr as &$v) {
    $v = $v;
}

$arr = [$arr];

var_dump(array_column($arr, 'name', 'id'));

Expected result:
----------------
array(1) {
  [12345]=>
  string(3) "sam"
}

Actual result:
--------------
array(1) {
  [0]=>
  &string(3) "sam"
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-02-25 08:07 UTC] laruence@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=c299b272c77b9bea4d6371a37a6d2b894f9729e8
Log: Fixed bug #71660 (array_column behaves incorrectly after foreach by reference)
 [2016-02-25 08:07 UTC] laruence@php.net
-Status: Open +Status: Closed
 [2016-07-20 11:33 UTC] davey@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=c299b272c77b9bea4d6371a37a6d2b894f9729e8
Log: Fixed bug #71660 (array_column behaves incorrectly after foreach by reference)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 13:01:29 2024 UTC