Bug #74077 [Opn]: Array_map with null argument inconsistency
| From: | cmb@php.net | Date: | Sat, 11 Feb 2017 18:38:02 +0000 |
| Subject: | Bug #74077 [Opn]: Array_map with null argument inconsistency | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-207271@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=74077&edit=1
ID: 74077
Updated by: cmb@php.net
Reported by: remyfox at hotmail dot com
Summary: Array_map with null argument inconsistency
Status: Open
Type: Bug
-Package: Unknown/Other Function
+Package: Arrays related
Operating System: Windows 10
PHP Version: 7.1.1
Block user comment: N
Private report: N
New Comment:
Alternative reproducer: <https://3v4l.org/DauMC>.
Not sure if that qualifies as bug (at least changing the behavior
would cause a considerable BC break), because the behavior is not
well documented at all.
Previous Comments:
------------------------------------------------------------------------
[2017-02-10 13:36:12] remyfox at hotmail dot com
Description:
------------
In the array map documentation (http://php.net/manual/en/function.array-map.php) under #4 there is
an example of using null as argument so as to make an array of arrays. This works fine for as long
one item is provided to the array_map function. However, if there are is just one item provided,
then the function will fail to be consistent.
Test script:
---------------
$two_item_array = [["abc", "def"], ["ghi", "jkl"]];
$one_item_array = [["abc", "def"]];
print_r(array_map(null, ...$two_item_array));
print_r(array_map(null, ...$one_item_array));
Expected result:
----------------
Array
(
[0] => Array
(
[0] => abc
[1] => ghi
)
[1] => Array
(
[0] => def
[1] => jkl
)
)
Array
(
[0] => Array
(
[0] => abc
)
[1] => Array
(
[0] => def
)
)
Actual result:
--------------
Array
(
[0] => Array
(
[0] => abc
[1] => ghi
)
[1] => Array
(
[0] => def
[1] => jkl
)
)
Array
(
[0] => abc
[1] => def
)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=74077&edit=1