Bug #80305 [Nab->Opn]: Call with the splat operator ignores by reference requirements

From: Date: Sun, 01 Nov 2020 16:28:52 +0000
Subject: Bug #80305 [Nab->Opn]: Call with the splat operator ignores by reference requirements
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-230057@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80305&edit=1 ID: 80305 Updated by: cmb@php.net Reported by: greedy dot ivan at gmail dot com Summary: Call with the splat operator ignores by reference requirements -Status: Not a bug +Status: Open Type: Bug Package: Scripting Engine problem Operating System: All PHP Version: 7.4.12 -Assigned To: cmb +Assigned To: Block user comment: N Private report: N New Comment: > This is a second issue when using the splat operator modifies > subsequent calls of call_user_func_array(). Like I said, this is not particularly releated to the splat operator, though. Previous Comments: ------------------------------------------------------------------------ [2020-11-01 16:18:52] greedy dot ivan at gmail dot com This is a second issue when using the splat operator modifies subsequent calls of call_user_func_array(). And this is a serious problem, because before this call, it does not change the argument that is not referenced, but starts doing it after. ------------------------------------------------------------------------ [2020-11-01 16:08:31] cmb@php.net > Passing arguments using the ... operator ignores requirements as > to which arguments must be passed by reference. The splat operator behaves as if the function was called directly[1]; actually, it is call_user_func_array() which doesn't behave correctly, but that is already filed as bug #70379. [1] <https://3v4l.org/Ro4Mn> ------------------------------------------------------------------------ [2020-11-01 15:39:00] greedy dot ivan at gmail dot com Description: ------------ 1. Passing arguments using the ... operator ignores requirements as to which arguments must be passed by reference. 2. Prevents warnings from subsequent calls that previously threw it (maybe it is some inner cache issue). https://3v4l.org/ksVmp Actually, there is a different behavior for 7.0, 7.3+, and 7.1 - 7.2. Test script: --------------- <?php $foo = function (int &$bar) { $bar++; }; $baz = 0; $args = [$baz]; call_user_func_array($foo, $args); echo $args[0]; call_user_func_array($foo, $args); echo $args[0]; $foo(...$args); echo $args[0]; call_user_func_array($foo, $args); echo $args[0]; call_user_func_array($foo, $args); echo $args[0]; Expected result: ---------------- Warning: Parameter 1 to {closure}() expected to be a reference, value given in /in/ksVmp on line 7 0 Warning: Parameter 1 to {closure}() expected to be a reference, value given in /in/ksVmp on line 10 0 Warning: Parameter 1 to {closure}() expected to be a reference, value given in /in/ksVmp on line 13 0 Warning: Parameter 1 to {closure}() expected to be a reference, value given in /in/ksVmp on line 16 0 Warning: Parameter 1 to {closure}() expected to be a reference, value given in /in/ksVmp on line 19 0 Actual result: -------------- Warning: Parameter 1 to {closure}() expected to be a reference, value given in /in/ksVmp on line 7 0 Warning: Parameter 1 to {closure}() expected to be a reference, value given in /in/ksVmp on line 10 0123 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=80305&edit=1

« previous php.bugs (#230057) next »