Bug #68553 [NEW]: array_column: null values in $index_key become incrementing keys in result

From: Date: Fri, 05 Dec 2014 16:46:04 +0000
Subject: Bug #68553 [NEW]: array_column: null values in $index_key become incrementing keys in result
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-188939@lists.php.net to get a copy of this message
From: ramsey@php.net Operating system: PHP version: 5.6.3 Package: Arrays related Bug Type: Bug Bug description:array_column: null values in $index_key become incrementing keys in result Description: ------------ When using $index_key to index the resulting array by a column from the original array, if null values are encountered, the resulting keys become integer values that are auto-incremented according to the previous integer key value (or start from 0, as a 0-indexed key). Test script with actual result and expected result is available here: https://gist.github.com/ramsey/da33c07d95bfd58ea29a Jan Roald Haugland first reported this issue on my blog: http://benramsey.com/blog/2013/03/introducing-array-column-in-php-5-dot-5/#comment-1660885919 Test script: --------------- See link to gist. Expected result: ---------------- NULL keys should be converted to empty strings, and multiple matching keys should be overwritten by the last value entered for that key. For example: $foo = [ null => 1, null => 2, null => 3 ]; becomes [ '' => 3 ] Actual result: -------------- With array_column(), NULL keys are being converted to 0-indexed integer key values, incrementing. So an array that gets evaluated to this and, therefore, should result in the expected array shown above: [ null => 1, null => 2, null => 3 ] ends up resulting in this: [ 0 => 1, 1 => 2, 2 => 3 ] See link to gist for full example and actual output. -- Edit bug report at https://bugs.php.net/bug.php?id=68553&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=68553&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=68553&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=68553&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=68553&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=68553&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=68553&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=68553&r=needscript Try newer version: https://bugs.php.net/fix.php?id=68553&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=68553&r=support Expected behavior: https://bugs.php.net/fix.php?id=68553&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=68553&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=68553&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=68553&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68553&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=68553&r=dst IIS Stability: https://bugs.php.net/fix.php?id=68553&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=68553&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=68553&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=68553&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=68553&r=mysqlcfg

« previous php.bugs (#188939) next »