In PHP, When we get to the optimization phase of the application (I am speaking about an app that handles hundreds of thousands of users) would it be smart to pass all arrays (where I do not mind what happens to them after I pass them to the function) by ref?
Share
PHP arrays have copy-on-write semantics. That means that new memory isn’t allocated for the new array until it is modified. For example:
Passing by reference might make a difference if the arrays are passed around between a lot of different methods and constantly modified in all these localized scopes. However, that would change the semantics of the application which means that this change is only possible if the arrays aren’t being modified.
That means that there’s no advantage at all to passing the arrays as references. Don’t do it.