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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

optional variables by reference

Status
Not open for further replies.

skiflyer

Programmer
Joined
Sep 24, 2002
Messages
2,213
Location
US
Anyone know if it's possible? I can't seem to make it work or find any documentation I just want..
Code:
function foo($arg1, $arg2, &$error_code=null) {

}

So if someone cares about the code they can have it, and if they don't, they don't get it.

I know I could put my main return as the by reference and return the error code for this behavior, but I'm just wondering if the above is possible.
 
I don't recall ever reading anywhere that his is not allowed, but if it were, it wouldn't make much sense.

The reason you use pass-by-value is so that the function can make permanent changes to the values in variables. What is your script going to do with the changed value if the value is a literal?


<aside>
I do remember that one version of FORTRAN had an interesting feature that if you passed a literal value to a function that both expected pass-by-reference and changed the value passed into it, the program would from the call to the function on understand that the literal referred to the new value.

The numeric literal 4 would, for example, have the value 5 when output or used in calculations.
</aside>




Want the best answers? Ask the best questions!

TANSTAAFL!!
 
And herein lies the problem... what I really want is an optional argument, not a preset variable which makes setting the argument optional.

Unfortunatley it results in a parse error, so I can't really surpress and ignore. So be it.
 
Ah yeah, good point.

I'm assuming you're referring to the func_get_args() (and similar) functions?

If so, wonderful thanks, if not, please elaborate.

Thanks, somehow I completely overlooked that option.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top