From: Operating system: Windows XP PHP version: 5.3.2 Package: Arrays related Bug Type: Bug Bug description:array_filter breaks references when a callback is used
Description: ------------ I have an array and a variable which is a reference on some element in this array: $arr=array('a'); $ref = &$arr[0] If I apply array_filter() with a callback like trim() or count() on the array, the reference is broken and $ref is no longer a reference (If I apply array_filter() without a callback, the reference is not altered and the result is correct). I think that this is a regression introduced in php 5.2.11: with the test script below, 5.2.10 give the good result, 5.2.11 do not. I also tested with the latest version (5.3.2): same result, reference is broken. PS: I tested on windows XP with packages php-5.x.y-Win32-VC6-x86.zip provided on this page: http://windows.php.net/downloads/releases/archives/ Test script: --------------- // Init $arr = array('some value'); $ref = & $arr[0]; // Change $arr $arr[0] = 'ONE'; echo 'step 1. $ref is ', ($ref !== 'ONE') ? 'BROKEN' : 'OK', "\n"; // Apply array_filter (without callback) and change $arr array_filter($arr); $arr[0] = 'TWO'; echo 'step 2. $ref is ', ($ref !== 'TWO') ? 'BROKEN' : 'OK', "\n"; // Apply array_filter (with a callback) then change $arr array_filter($arr,'trim'); $arr[0] = 'THREE'; echo 'step 3. $ref is ', ($ref !== 'THREE') ? 'BROKEN' : 'OK', "\n"; Expected result: ---------------- step 1. $ref is OK step 2. $ref is OK step 3. $ref is OK Actual result: -------------- step 1. $ref is OK step 2. $ref is OK step 3. $ref is BROKEN -- Edit bug report at http://bugs.php.net/bug.php?id=51986&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=51986&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=51986&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=51986&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=51986&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=51986&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=51986&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=51986&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=51986&r=needscript Try newer version: http://bugs.php.net/fix.php?id=51986&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=51986&r=support Expected behavior: http://bugs.php.net/fix.php?id=51986&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=51986&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=51986&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=51986&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=51986&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=51986&r=dst IIS Stability: http://bugs.php.net/fix.php?id=51986&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=51986&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=51986&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=51986&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=51986&r=mysqlcfg