Reputation: 3367
Since PHP objects are passed by reference(reference to the object itself, not to be confused with reference to the variable), does passing a very large object to a function add any resource stress to the system?
This seems like a 'get out of jail free card' for passing information, Since no copies are being made, I can pass a huge object around, while if I pass an array I take a memory hit.
In my OOP coding style, I prefer passing entire objects as arguments instead of just a single attribute, as it makes the code more readable and allows for greater functionality down the road if it's needed.
So my questions :
Thanks in advance!
Upvotes: 0
Views: 61
Reputation: 41968
Bonus answer:
As for this line:
In my OOP coding style, I prefer passing entire objects as arguments instead of just a single attribute, as it makes the code more readable and allows for greater functionality down the road if it's needed.
I'm curious about what you mean with that. It sounds a lot like you're sacrificing OOP principles to cover up for architectural mistakes. As a rule of thumb, any interface to any object should pass the least possible information around. Just passing entire objects or arrays around 'for convenience' sounds like very bad architecture or coding style.
Upvotes: 1