Bug #69778 [NEW]: array_filter() modifies var out of scope when used with cb accepting by ref

From: Date: Tue, 09 Jun 2015 00:01:07 +0000
Subject: Bug #69778 [NEW]: array_filter() modifies var out of scope when used with cb accepting by ref
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-193223@lists.php.net to get a copy of this message
From: kernins at gmail dot com Operating system: Debian PHP version: 5.6.9 Package: Arrays related Bug Type: Bug Bug description:array_filter() modifies var out of scope when used with cb accepting by ref Description: ------------ See the code, it explains better than words. I've explicitly mentioned array_filter(), coz the bug is 100% reproducible with this function, but array_walk/map() works as expected. Confirmed on 5.6.9-1~dotdeb+7.1 and 5.4.34-1~dotdeb.0 Both are CLI, didn't tested on FPM Test script: --------------- $arr=[' ', ' foo ', ' ', ' bar ', 'baz ', ' ']; function something(array $arg) { array_filter($arg, function(&$el){return strlen($el=trim($el));}); } var_dump($arr); something($arr); var_dump($arr); Expected result: ---------------- Both var_dumps should print the original array array(6) { [0]=> string(3) " " [1]=> string(7) " foo " [2]=> string(3) " " [3]=> string(8) " bar " [4]=> string(6) "baz " [5]=> string(2) " " } Actual result: -------------- However the second var_dump actually prints the modified one array(6) { [0]=> string(0) "" [1]=> string(3) "foo" [2]=> string(0) "" [3]=> string(3) "bar" [4]=> string(3) "baz" [5]=> string(0) "" } despite $arr was passed to something() by value, not reference. -- Edit bug report at https://bugs.php.net/bug.php?id=69778&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69778&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69778&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69778&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=69778&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=69778&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=69778&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=69778&r=needscript Try newer version: https://bugs.php.net/fix.php?id=69778&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=69778&r=support Expected behavior: https://bugs.php.net/fix.php?id=69778&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=69778&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=69778&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=69778&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69778&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=69778&r=dst IIS Stability: https://bugs.php.net/fix.php?id=69778&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=69778&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=69778&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=69778&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=69778&r=mysqlcfg

« previous php.bugs (#193223) next »