|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2021-03-15 16:33 UTC] cmb@php.net
-Status: Open
+Status: Wont fix
-Assigned To:
+Assigned To: cmb
[2021-03-15 16:33 UTC] cmb@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 09:00:01 2025 UTC |
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);