I call a function with 2 params sent by reference:

if (!functionX($arg1, $arg2, $arg3, $arg2, &$error, &$error_msg)) {
// blah blah
}

The idea is that this code lives in a form handler and it needs to return true or false but I need some extra information if it returns false so I sent the error vars by reference so they can be modified.

I recently updated to php 5 and now get this error:

Warning: 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 functionX(). 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 /var/www/html/fileX.php on line 213

The function definition starts like this - it also has the & for passing by reference.

function prelim_validate_cc_num($arg1, $arg2, $arg3, $arg4, &$error, &$error_msg) {
 // blah blah blah
}

Is it enough to remove the ampersands from the function call or do I need to restructure my function?

    References in the function declaration aren't the problem; the problem is a reference in the function call.

    function foo(&$a) { .... }

    is fine. What's not is

    $bar = bar(&$a);

      OK I feel much reassured. The function in question is pretty sensitive but this code behaves pretty much as I thought:

      <?
      function foo($arg1, &$error) {
        $error .= "<br>ADDED ERROR TEXT: Sorry, $arg1 is not a valid arg";
        return false;
      }
      
      $error = "ORIGINAL: Here is the original text";
      
      if (!foo('YOUR MOMMA', $error)) {
        echo 'rats it failed, error was ' . $error;
      }
      ?>
      

      output:

      rats it failed, error was ORIGINAL: Here is the original text
      ADDED ERROR TEXT: Sorry, YOUR MOMMA is not a valid arg

      As you described, putting the ampersand into the if statement causes the error:

      if (!foo('YOUR MOMMA', &$error)) {
        echo 'rats it failed, error was ' . $error;
      }
      

        Incidentally, you might want to use the <?php open tag instead of the short open tag <?.

        Oh, and remember to mark this thread as resolved (if it is) using the thread tools.

          Write a Reply...