Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is passing variables by reference deprecated?

There is a comment on an answer on SO:

Code in answer:

$larry = & $fred;

Comment:

This is deprecated and generates a warning

But I don't think it is correct. Or is it?

So basically the question is:

can I copy a variable to another variable by reference?

like image 271
PeeHaa Avatar asked Nov 25 '11 21:11

PeeHaa


1 Answers

Depends on what type variable $fred is. If it's an object, it will be passed as reference a pointer to the object (thanks NikiC) will be passed as value anyway as of PHP 5, so there is no need to explicitly do it. Thus far, the comment is correct-ish.

For all other variable types, however, passing by reference needs to be explicitly specified and is not deprecated. Although it could be argued that it's usually not good programming practice to use a lot of references in PHP.

like image 95
Pekka Avatar answered Sep 29 '22 06:09

Pekka