Req #60662 [Opn->Wfx]: Additional argument for array_map to ignore references

From: Date: Mon, 15 Mar 2021 16:33:23 +0000
Subject: Req #60662 [Opn->Wfx]: Additional argument for array_map to ignore references
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-232740@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=60662&edit=1 ID: 60662 Updated by: cmb@php.net Reported by: phpmpan at mpan dot pl Summary: Additional argument for array_map to ignore references -Status: Open +Status: Wont fix Type: Feature/Change Request Package: Arrays related Operating System: Any PHP Version: 5.3.8 -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: Besides that this use-case isn't compelling to me, optional parameters are no longer allowed to precede required parameters for *userland* functions as of PHP 8.0.0. While that is still possible for internal functions, it results in a big mess regarding named arguments. As such, we won't implement this. If you feel strongly about it, please pursue the RFC process[1]. [1] <https://wiki.php.net/rfc/howto> Previous Comments: ------------------------------------------------------------------------ [2012-01-05 03:05:59] phpmpan at mpan dot pl 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 this bug report at https://bugs.php.net/bug.php?id=60662&edit=1

« previous php.bugs (#232740) next »