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:
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2017 The PHP Group
All rights reserved.
Last updated: Tue Feb 21 19:01:38 2017 UTC