php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50748 func_get_args() should be able to pass variables as reference
Submitted: 2010-01-14 11:00 UTC Modified: 2010-01-14 11:36 UTC
From: gahgneh+php at gmail dot com Assigned:
Status: Not a bug Package: Variables related
PHP Version: 5.2.12 OS: Windows XP SP3
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: gahgneh+php at gmail dot com
New email:
PHP Version: OS:

 

 [2010-01-14 11:00 UTC] gahgneh+php at gmail dot com
Description:
------------
func_get_args() should be able to pass variables as reference

Reproduce code:
---------------
function ref(){
  $args = func_get_args();
  $args[0] = 10;
  $args[1] = 11;
}

$value = 0;
$value2 = 1;
ref($value, $value2);

echo $value,$value2; // prints 01

Expected result:
----------------
$value to contain "int 10" and $value2 to contain "int 11"
There should be a * pointer operator like C++, to tell the variable to behave like
function ref(int* p = null){ *p = 10; }


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-01-14 11:16 UTC] johannes@php.net
For passing references we would need to know at the time the parameters are prepared, before actually invoking the function, that references are expected. That can only be done by defining it in the signature ... but when doing that func_get_args() is rather useless - the only case would be an undefined number of reference parameters which can be simulated by using an array of references as parameter ... but then again: There's barely any reason for using references these days in PHP.
 [2010-01-14 11:36 UTC] gahgneh+php at gmail dot com
I usually prefer to check if the variable(s) are empty before calling indexes on them. Or make it able to func_get_args() to pass variables by reference, or extend isset() and empty() to check multiple items. If the parameter is not a reference, PHP gives a undefined index notice.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Mar 03 13:01:28 2024 UTC