开发者

Benefit of passing by reference? (php) [duplicate]

This question already has answers here: Closed 11 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜