Bug #79850 [Opn]: array_walk / array_filter incorrectly warn variables should be passed by ref

From: Date: Mon, 13 Jul 2020 12:54:46 +0000
Subject: Bug #79850 [Opn]: array_walk / array_filter incorrectly warn variables should be passed by ref
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-228005@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79850&edit=1

 ID:                 79850
 Updated by:         nikic@php.net
 Reported by:        sjon@php.net
 Summary:            array_walk / array_filter incorrectly warn variables
                     should be passed by ref
 Status:             Open
 Type:               Bug
 Package:            Arrays related
 Operating System:   archLinux
 PHP Version:        8.0.0alpha2
 Block user comment: N
 Private report:     N

 New Comment:

This is an intentional change, now documented with https://github.com/php/php-src/commit/2edc5e00ac5ceef6429c3ef4651745efa97a13d8.

As the the inverted message, I can see where you're coming from there... The message appears
because array_filter() internally calls the callback with a value, but the function expects a
reference, thus the warning in this form.


Previous Comments:
------------------------------------------------------------------------
[2020-07-13 12:21:33] sjon@php.net

Description:
------------
I'm not 100% sure this is a bug but both array_walk and array filter throw warnings when
variables are passed by reference. Either the message is inverted (they don't accept variables
by reference) or it's incorrectly thrown

Originally found as https://3v4l.org/WH94Q

Test script:
---------------
$ids = array("8479");

$newIds = array_filter($ids, function(&$n) {
                $n = intVal($n);
            });


Expected result:
----------------
no warning

Actual result:
--------------
Warning: {closure}(): Argument #1 ($n) must be passed by reference, value given in /in/WH94Q on line
7


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=79850&edit=1


Thread (4 messages)

« previous php.bugs (#228005) next »