From: Operating system: Any PHP version: 5.3.8 Package: Arrays related Bug Type: Feature/Change Request Bug description:Additional argument for array_map to ignore references
Description: ------------ If a callback function for array_map calls array_map again for array arguments, it is possible to cause infinite recursion for arrays with cyclic references. While this is NOT a bug and everything works as expected, it would be nice to have a flag to array_map, that address this issue. Current syntax for array_map prevents adding new parameters at the end (arguments for the callback go there). However an additional optional parameter may be added at the begining. Since the first argument is always a callback, the form with additional flags can be easily distinguished: array_map(callback, array, ...) <-- old form array_map(non-callback, callback, array, ...) <-- with flags as 1st arg Test script: --------------- // WARNING: CAUSES INFINITE RECURSION! function fn($arg) { if (is_array($arg)) { return array_map('fn', $arg); } else { return $arg; // in a real code something will be done here } } $array = array(1, 2, 3); $array[] = &$array; fn($array); -- Edit bug report at https://bugs.php.net/bug.php?id=60662&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=60662&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=60662&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=60662&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=60662&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=60662&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=60662&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=60662&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=60662&r=needscript Try newer version: https://bugs.php.net/fix.php?id=60662&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=60662&r=support Expected behavior: https://bugs.php.net/fix.php?id=60662&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=60662&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=60662&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=60662&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=60662&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=60662&r=dst IIS Stability: https://bugs.php.net/fix.php?id=60662&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=60662&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=60662&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=60662&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=60662&r=mysqlcfg