Re: Passing variable number of parameters by reference

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I believe it's mentioned somewhere in the manual you can't do that. func_get_arg() always return a copy. You can workaround this using an array.

Robert Meyer wrote:
Hello,

Using: PHP Version 5.0.3

I build the following function:

    function Set4HTMLOut() {
      $C = func_num_args();
      for ($I = 0; $I < $C; $I++) {
        $A = func_get_arg($I);
 echo 'I['.$I.']('.strlen($A).'): '.$A.'<br />';
        $A = htmlspecialchars($A);
 echo 'I['.$I.']('.strlen($A).'): '.$A.'<br />';
      }
    }

And called it like this:

     Set4HTMLOut(&$LName, &$LOrg, &$LWebSite, &$LPhones, &$LComments);
 echo '<br />After call:<br />'.
         'LName: '.$LName.'<br />'.
         'LOrg: '.$LOrg.'<br />'.
         'LWebSite: '.$LWebSite.'<br />'.
         'LPhones: '.$LPhones.'<br />'.
         'LComments: '.$LComments.'<br />';

The "echo" statements in the Set4HTMLOut() function echos all the correct data and proves the data was received correctly then altered by the htmlspecialchars() function appropriately. Notice that the caller passes each variable as a reference. Yet, the "echo" statement after the call displays the data without any changes, like the first "echo" statement in the Set$HTMLOut() function does.

Is it not possible to pass variables by reference to a variable-length parameter list? Or am I doing something wrong? If so, what?

I have already built a work around. I do not need any work arounds. I just think one should be able to pass variables by reference to a function that accepts a variable-length parameter list.

Regards

Robert


-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux