Bug #76587 [NEW]: array_column gives incorrect result if $indexKey selects a float

From: Date: Fri, 06 Jul 2018 13:14:44 +0000
Subject: Bug #76587 [NEW]: array_column gives incorrect result if $indexKey selects a float
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-216168@lists.php.net to get a copy of this message
From: rowan dot collins at gmail dot com Operating system: PHP version: 7.2.7 Package: Arrays related Bug Type: Bug Bug description:array_column gives incorrect result if $indexKey selects a float Description: ------------ When array_column is used with the $indexKey parameter, and the selected index is a float, it is ignored, and treated as an array-append operation. This is unexpected, because attempting to use a float as a key would normally result in it being cast to either an integer or a string. Note that this is similar to Bug #68553, where null keys are also treated as array-appends. As with that bug, the polyfill implemented in userland behaves as expected. HHVM's implementation seems to cast all floats to integer, so float(2.5) becomes int(2) rather than string("2.5"). Test script: --------------- $a = [ [ 'foo' => 1.0 ], [ 'foo' => 2.5 ], [ 'foo' => 3 ], [ 'foo' => '4' ], ]; var_dump(array_column($a, 'foo', 'foo')); Expected result: ---------------- array(4) { [1] => float(1) ["2.5"] => float(2.5) [3] => int(3) [4] => string(1) "4" } Actual result: -------------- array(4) { [0] => float(1) [1] => float(2.5) [3] => int(3) [4] => string(1) "4" } -- Edit bug report at https://bugs.php.net/bug.php?id=76587&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=76587&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=76587&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=76587&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=76587&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=76587&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=76587&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=76587&r=needscript Try newer version: https://bugs.php.net/fix.php?id=76587&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=76587&r=support Expected behavior: https://bugs.php.net/fix.php?id=76587&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=76587&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=76587&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=76587&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76587&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=76587&r=dst IIS Stability: https://bugs.php.net/fix.php?id=76587&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=76587&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=76587&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=76587&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=76587&r=mysqlcfg

« previous php.bugs (#216168) next »