Bug #65904 [NEW]: array_keys($array, null) does not behave the same as array_keys($array)

From: Date: Tue, 15 Oct 2013 19:30:12 +0000
Subject: Bug #65904 [NEW]: array_keys($array, null) does not behave the same as array_keys($array)
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-182299@lists.php.net to get a copy of this message
From: avi at alphapipe dot com Operating system: Ubuntu 12.04.3 LTS PHP version: 5.4.20 Package: Arrays related Bug Type: Bug Bug description:array_keys($array, null) does not behave the same as array_keys($array) Description: ------------ According to the documentation at http://php.net/manual/en/function.array-keys.php, the default value for the second parameter in array_keys ($search_value) is null. However, if you call the function and pass in null as the second value, the function returns an empty array, instead of the array of keys (as it appears to be searching for actual keys that match null). Shouldn't a function behave the same way if a parameter is left blank or if the default value is passed in? Test script: --------------- <?php $muppetColors = [ 'fozzie' => 'orange', 'kermit' => 'green' ]; print_r(array_keys($muppetColors)); print_r(array_keys($muppetColors, null)); Expected result: ---------------- Both print_r statements should return arrays [ 'fozzie', 'kermit' ]. Actual result: -------------- The first print_r statement returns the expected array [ 'fozzie', 'kermit' ], but the second print_r returns an empty array. -- Edit bug report at https://bugs.php.net/bug.php?id=65904&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=65904&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=65904&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=65904&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=65904&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=65904&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=65904&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=65904&r=needscript Try newer version: https://bugs.php.net/fix.php?id=65904&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=65904&r=support Expected behavior: https://bugs.php.net/fix.php?id=65904&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=65904&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=65904&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=65904&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65904&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=65904&r=dst IIS Stability: https://bugs.php.net/fix.php?id=65904&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=65904&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=65904&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=65904&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=65904&r=mysqlcfg

« previous php.bugs (#182299) next »