NYCPHP Meetup

NYPHP.org

[nycphp-talk] Why is pass-by-reference deprecated?

Cliff Hirsch cliff at pinestream.com
Mon Nov 19 15:01:30 EST 2007


On 11/19/07 1:27 PM, "Gary Mort" <bz-gmort at beezifies.com> wrote:
> Cliff Hirsch wrote:
>> The php manual says:
>> ³In recent versions of PHP you will get a warning saying that
>> "Call-time pass-by-reference" is deprecated when you use a & in foo(&$a);²
>> Why is this? Besides being ugly, difficult to understand and not very
>> elegant, is there any reason technical reason why this is deprecated?
>> 
> Because if you declare it in the function:
> function foo(&$mya) {
> }
> 
> Than you have told PHP that whenever this function is used, variables
> should be passed by reference and not copied.
> 
> So the thinking is, you should know ahead of time whether or not you
> want to pass by reference or pass a copy, and not decide to do it at the
> time you call your code.
> 
> IE, don't do:
> foo(&$a);

Ah, I got it. Pass-by-reference in the function call is what's depricated.
As in foo(&$a); (as you noted above).

Pass-by-reference in the function definition is not depricated. As in
public function Thefunction(&$varref) {
}

Still ugly and error prone compared to clean oop, but passing objects around
is sort of the same thing and infinitely more confusing.





More information about the talk mailing list
Automatic Email Organization without missing anything!