Doc #65904 [Ver->Csd]: array_keys($array, null) does not behave the same as array_keys($array)
| From: | frozenfire@php.net | Date: | Tue, 31 Dec 2013 20:15:04 +0000 |
| Subject: | Doc #65904 [Ver->Csd]: array_keys($array, null) does not behave the same as array_keys($array) | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-10784@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=65904&edit=1
ID: 65904
Updated by: frozenfire@php.net
Reported by: avi at alphapipe dot com
Summary: array_keys($array, null) does not behave the same as
array_keys($array)
-Status: Verified
+Status: Closed
Type: Documentation Problem
Package: Arrays related
Operating System: Ubuntu 12.04.3 LTS
PHP Version: 5.4.20
-Assigned To:
+Assigned To: frozenfire
Block user comment: N
Private report: N
New Comment:
The fix for this bug has been committed.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
For Windows:
http://windows.php.net/snapshots/
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2013-12-31 20:14:32] frozenfire@php.net
Automatic comment from SVN on behalf of frozenfire
Revision: http://svn.php.net/viewvc/?view=revision&revision=332548
Log: Removed initializer from the search_value parameter, as it was incorrect and confusing.
Fixes bug #65904.
------------------------------------------------------------------------
[2013-10-15 19:52:33] bwoebi@php.net
Actually this is a documentation problem. array_keys() has no default value for the second
parameter. (Reason: You might want to search for keys where value is equal to null.)
------------------------------------------------------------------------
[2013-10-15 19:30:12] avi at alphapipe dot com
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 this bug report at https://bugs.php.net/bug.php?id=65904&edit=1