php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47693 func_get_args returns copies of arguments, not referenced values
Submitted: 2009-03-17 16:43 UTC Modified: 2009-03-17 17:43 UTC
From: joffrey at coolhaven dot info Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3CVS-2009-03-17 (CVS) OS: Linux
Private report: No CVE-ID: None
 [2009-03-17 16:43 UTC] joffrey at coolhaven dot info
Description:
------------
Calling func_get_args() returns copies of the arguments of the function. It would be more useful to return referenced values if those are defined in the function parameters.

This is useful when using func_get_args() for function parameter overloading and calling other functions from a function using call_user_func_array().

A bit off topic: I see var_dump is aware if the variable is a referenced one. Would it be possible to implement a 'is_reference()' function now?

Reproduce code:
---------------
$a = 1;
$b = 2;
$c = "3";

function f($a, &$b, &$c)
  {
  var_dump(func_get_args());
  }

var_dump(array($a, &$b, &$c));

f($a, $b, $c);


Expected result:
----------------
array(3) {
  [0]=>
  int(1)
  [1]=>
  ∫(2)
  [2]=>
  &string(1) "3"
}
array(3) {
  [0]=>
  int(1)
  [1]=>
  ∫(2)
  [2]=>
  &string(1) "3"
}

Actual result:
--------------
array(3) {
  [0]=>
  int(1)
  [1]=>
  ∫(2)
  [2]=>
  &string(1) "3"
}
array(3) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  string(1) "3"
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-03-17 16:55 UTC] joffrey at coolhaven dot info
All of a sudden I realized a catch 22: you know which parameters are call-by-reference because you must define them in your function.

This makes the use of referenced values in func_get_args() not essential but practical. Not only for the sake of completeness but also useful in combination with call_user_func_array().
 [2009-03-17 17:43 UTC] scottmac@php.net
When you call func_get_args() it can't possibly know which ones are meant to be referenced and which aren't because the function definition is what indicates the reference.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 21:01:36 2024 UTC