Req #78257 [Opn->Nab]: default arguments by reference don't work
Edit report at https://bugs.php.net/bug.php?id=78257&edit=1
ID: 78257
Updated by: nikic@php.net
Reported by: amillanir1991 at gmail dot com
Summary: default arguments by reference don't work
-Status: Open
+Status: Not a bug
Type: Feature/Change Request
Package: *Compile Issues
Operating System: Windows 7 64 bits
PHP Version: 7.3Git-2019-07-05 (snap)
Block user comment: N
Private report: N
New Comment:
$arr[0] = 100 overwrites the first argument entirely. If you want to modify the array passed as
first argument, you need $arr[0][0] = 100.
Doing a var_dump($arr) after asign($arr) should make this more obvious.
Previous Comments:
------------------------------------------------------------------------
[2019-07-05 22:35:16] amillanir1991 at gmail dot com
the value that show is the type NULL
------------------------------------------------------------------------
[2019-07-05 22:24:40] amillanir1991 at gmail dot com
Description:
------------
function that recieve default arguments by reference don´t work, php version 7.3.6 exactly.
Test script:
---------------
//Don´t work
$arr = [10];
function asign(&..$arr){
$arr[0] = 100;
}
asign($arr);
echo "<br> $arr[0]";
//Work
$arr = [10];
function asign(&$arr){
$arr[0] = 100;
}
asign($arr);
echo "<br> $arr[0]";
Expected result:
----------------
that the value changed into function
Actual result:
--------------
it shows nothing on the screen, not even a warning ...
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=78257&edit=1
Thread (4 messages)