I also had to work with a codebase that had function calls like this. Fortunately, I had access to the developers who wrote the code. Here is what I learned.
Scenario 1:
Just a way to document the code. You know the name of the variable that you pass to the function.
Scenario 2:
Here is the link: http://www.php.net/manual/en/language.references.pass.php If you see, they specifically call your case:
foo($a = 5); // Expression, not variable
A 'dummy' pass-by-ref. Depending on your version of PHP, this may cause a warning. I got this: Strict Standards: Only variables should be passed by reference in ...
Now let me tell you in detail about what is happening in this situation.
The danger is that your example you provided does not display "gotcha!". behavior. In this case, your $arg2 , which you echo away from the function, will always be what it is in the function call. In addition, the called function will also be sent a βcopyβ of this value and will work with it. I say "copy" because, although the function requires omissions, it actually gets a copy, similar to what the normal parameter of the function will receive.
If you change $arg2 , which is inside the function, it WILL NOT change $arg2 , which is outside the function, as you would expect from a function that passes through -REF.
CenterOrbit
source share