开发者

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

开发者 https://www.devze.com 2023-03-14 07:58 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: In PHP (>= 5.0), is passing by reference faster?
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

精彩评论

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