Bug #71240 [Nab]: array_filter byref value in callable no longer working
[email protected] ("donatj at gmail dot com")
| Newsgroups | php.bugs |
|---|---|
| Message-ID | <[email protected]> |
Edit report at https://bugs.php.net/bug.php?id=71240&edit=1
ID: 71240
User updated by: donatj at gmail dot com
Reported by: donatj at gmail dot com
Summary: array_filter byref value in callable no longer
working
Status: Not a bug
Type: Bug
Package: *General Issues
PHP Version: 7.0.1
Block user comment: N
Private report: N
New Comment:
I still argue it's a bug. It's a behaviour that goes way back to at least 4.3.0 https://3v4l.org/iTqYI
If nothing else, the change should be noted in the array_filter documentation, but I'd still argue it should be fixed.
Previous Comments:
------------------------------------------------------------------------
[2015-12-29 22:22:25] [email protected]
@requinix: Actually I'm just stupid, you are totally right. I got confused with which output is which.
------------------------------------------------------------------------
[2015-12-29 21:03:42] [email protected]
Fair enough. It just looked like one more of the various inconsistencies with references that was fixed with 7.
------------------------------------------------------------------------
[2015-12-29 20:58:52] [email protected]
@requinix: The issue here is that is does the by-reference modification, while it should not. A similar, but slightly different, bug exists in HHVM as well: https://3v4l.org/dp6Lt
------------------------------------------------------------------------
[2015-12-29 20:57:12] [email protected]
I don't see anything to suggest that was supported in the first place. There aren't even user comments doing that.
Besides, if you want to alter the array values then array_map() is more appropriate.
------------------------------------------------------------------------
[2015-12-29 20:05:12] donatj at gmail dot com
Description:
------------
It would appear that passing by reference in the callable of array_filter no longer functions as expected. I can find no documentation of this change on the array_filter page.
The expected result is seen in 5.3 -> 5.6
Test script:
---------------
<?php
$files = array('AAA', 'BBB', 'CcC');
$files = array_filter($files, function ( &$path ) {
$path = strtolower($path);
return true;
});
print_r($files);
Expected result:
----------------
Array
(
[0] => aaa
[1] => bbb
[2] => ccc
)
Actual result:
--------------
Array
(
[0] => AAA
[1] => BBB
[2] => CcC
)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71240&edit=1