php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31606 Bogus warning message on legitimate pass by reference w/ variable function name
Submitted: 2005-01-19 11:03 UTC Modified: 2005-01-19 12:42 UTC
From: gutzas at moongate dot ro Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 4.3.10 OS: Fedora Linux
Private report: No CVE-ID: None
 [2005-01-19 11:03 UTC] gutzas at moongate dot ro
Description:
------------
Passing by reference when the function is called as variable generates a warning message, even if the function does accept its parameters by reference.

The actual behaviour is however correct, even though the warning says that the argument has been passed by value.

This is a major problem for intensively used sites where this functionality is needed and warning messages are logged because the logs grow to unmanageable sizes really fast.


Reproduce code:
---------------
<?

  function foo(&$param)
  {
    $param++;
  }

  $function_name='foo';
  $myParam=1;
  $function_name(&$myParam);
  echo("\n---> $myParam <---\n");

?>


Expected result:
----------------
---> 2 <---


Actual result:
--------------
<br />
<b>Warning</b>:  Call-time pass-by-reference has been deprecated - argument passed by value;  If you would like to pass it by reference, modify the declaration of [runtime function name]().  If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file.  However, future versions may not support this any longer.  in <b>/var/www/html/mgv/dev/helpdesk_root/helpdesk/test_reference.php</b> on line <b>10</b><br />

---> 2 <---


Patches

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-19 11:07 UTC] derick@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions. 

Thank you for your interest in PHP.

Remove the & from the call!
 [2005-01-19 11:59 UTC] gutzas at moongate dot ro
I *need* to pass that variable by reference, my code is correct, and PHP issues a warning which has nothing to do with reality. How can that not be a bug?!

Obviously, the code I posted in the bug is the most canonical form I could find to reproduce the bug. In this sample case I could have passed the argument by value proper, but in my production code I need it to be passed by reference, and I need to pass it via a variable function name.
 [2005-01-19 12:40 UTC] derick@php.net
Your function definition already has a & which makes the variable pass by reference. So you do not need the & when *calling* the function.
 [2005-01-19 12:42 UTC] gutzas at moongate dot ro
I understand, and yes, it works properly that way. Thank you, and sorry for wasting your time.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Aug 17 23:01:27 2024 UTC