Benefit of passing by reference? (php) [duplicate]
Possible Duplicate:
In PHP (>= 5.0), is passing by reference faster?
I know the use of passing by reference. I'm wondering specifically is there some resource and/or performance benefit to passing by reference? Do I keep cleaner memory resources by passing, for instance PDO objects, by referen开发者_StackOverflow社区ce instead of value? I think php5 automatically passes objects by reference by default right?
Passing by reference is faster. PHP5 do pass objects by reference by default. I think under PHP 5.3, you still have to do $obj = &new Object();
, but I could be wrong about that.
PHP5 do not pass array by reference. If you want to modify them in a function, you need to pass by reference.
Passing by value means that every single value is copied. For example, if you pass an array by value, it copies the array to a different memory location and every single element in it.
PHP References Explained and Objects and references might be of some help.
精彩评论