开发者

Does PHP copy object data structures when I pass objects to functions or methods?

I know there's the option to pass开发者_开发问答 a value by reference, simply by writing something like

function foo(&$bar) {...}

But from Objective-C I'm used to believe that objects are always passed by reference (since the variables referencing them are just pointers whose values are just a memory address). Only sctructures and primitives would have to explicitely be passed by reference.

How's that going on in PHP? Must I be sure to put that address operator & into every parameter to enhance performance when passing objects?


Only in versions prior to PHP5. In PHP5 objects are always passed by reference.


PHP5 passes object by reference. To pass them by value you can use the keyword clone.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜