php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #78257 default arguments by reference don't work
Submitted: 2019-07-05 22:24 UTC Modified: 2019-07-05 22:43 UTC
From: amillanir1991 at gmail dot com Assigned:
Status: Not a bug Package: *Compile Issues
PHP Version: 7.3Git-2019-07-05 (snap) OS: Windows 7 64 bits
Private report: No CVE-ID: None
 [2019-07-05 22:24 UTC] 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 ...

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-07-05 22:35 UTC] amillanir1991 at gmail dot com
the value that show is the type NULL
 [2019-07-05 22:43 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2019-07-05 22:43 UTC] nikic@php.net
$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.
 [2019-07-06 01:35 UTC] amillanir1991 at gmail dot com
thank you very much !!!!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 15:01:29 2024 UTC