Bug #71240 [Nab]: array_filter byref value in callable no longer working
| From: | nikic@php.net | Date: | Tue, 29 Dec 2015 23:11:55 +0000 |
| Subject: | Bug #71240 [Nab]: array_filter byref value in callable no longer working | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-198296@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=71240&edit=1
ID: 71240
Updated by: nikic@php.net
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:
array_filter() is documented as taking the $array by value. It's not *allowed* to modify the
original array in any way. Modifying the array violates basic semantics of by-value argument
passing.
Previous Comments:
------------------------------------------------------------------------
[2015-12-29 22:46:13] donatj at gmail dot com
Also the use case for this - I'm array_filter-ing already, not with a hardcoded true but actual
logic, and as the code is already looping over items having a second loop through my array with
array_map is silly.
------------------------------------------------------------------------
[2015-12-29 22:39:22] donatj at gmail dot com
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.
------------------------------------------------------------------------
[2015-12-29 22:22:25] nikic@php.net
@requinix: Actually I'm just stupid, you are totally right. I got confused with which output is
which.
------------------------------------------------------------------------
[2015-12-29 21:03:42] requinix@php.net
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] nikic@php.net
@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
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=71240
--
Edit this bug report at https://bugs.php.net/bug.php?id=71240&edit=1