Bug #75130 [Opn->Nab]: array_filter pass-by-ref broken

From: Date: Mon, 28 Aug 2017 12:27:43 +0000
Subject: Bug #75130 [Opn->Nab]: array_filter pass-by-ref broken
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-210851@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75130&edit=1 ID: 75130 Updated by: nikic@php.net Reported by: kernins at gmail dot com Summary: array_filter pass-by-ref broken -Status: Open +Status: Not a bug Type: Bug Package: Arrays related Operating System: Linux x86_64 PHP Version: 7.1.8 Block user comment: N Private report: N New Comment: If a function doesn't explicitly document that it's operating on references (such as array_walk), then you can generally assume that it does not work with references. The correct way to write this code is a combination of array_map and array_filter. Previous Comments: ------------------------------------------------------------------------ [2017-08-28 12:11:52] kernins at gmail dot com Description: ------------ Passing array element to callback by ref doesn't work anymore, resulting array contains original/unmodified values Test script: --------------- $arr=['foo', 'bar', '', 'baz']; $arr=array_filter($arr, function(&$el){ $el=strtoupper($el); return strlen($el)>0; }); var_dump($arr); Expected result: ---------------- array(3) { [0]=> string(3) "FOO" [1]=> string(3) "BAR" [3]=> string(3) "BAZ" } Actual result: -------------- array(3) { [0]=> string(3) "foo" [1]=> string(3) "bar" [3]=> string(3) "baz" } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75130&edit=1

« previous php.bugs (#210851) next »