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

From: Date: Sun, 01 Nov 2020 16:08:31 +0000
Subject: Bug #80305 [Opn->Nab]: Call with the splat operator ignores by reference requirements
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-230055@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: Open +Status: Not a bug Type: Bug -Package: *General Issues +Package: Scripting Engine problem Operating System: All PHP Version: 7.4.12 -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: > 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> Previous Comments: ------------------------------------------------------------------------ [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 (#230055) next »