Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Allowing Optional 'Pass by Reference' parameters? 1

Status
Not open for further replies.

OmniCog

Programmer
Jan 23, 2004
27
0
0
CA
How can I make a parameter that is passed by reference optional?

IE)
function xyz ($param1, $param2, &$errors) {
...
}

so that something like:
xyz ($param1, $param2);
would still work and not require a '@' to supress warning messages.
 
One way, not very elegant, is to define your function to accept pass-by-value inputs with default values, then pass the function a reference in the third parameter:

Code:
<?php

function foo ($x, $y, $z = '__DUMMY__VALUE__')
{
   if ($z != '__DUMMY__VALUE__')
   {
      $foo =& $z;
      $foo =  4;
   }
}

$a = 3;
foo(1, 2, &$a);
print $a;

?>

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top