NYCPHP Meetup

NYPHP.org

[nycphp-talk] Optimal Object, property, variable passing strategy between classes

Cliff Hirsch cliff at pinestream.com
Thu Jul 14 12:08:10 EDT 2005


This may be a newbie question, but I am confused regarding the most
optimal way to pass information between classes, especially if I want
access to a variable, say for example a product name to be used in an
email alert, but don't need to modify it. I come across this situation
frequently when one class becomes bloated and I decide to split it off
into several more logically partitioned classes.
 
If I use arguments in functions, I believe the values are copied, which
would seem to be slow. As one function calls another function and so on,
it seems like needless copies of a variable are made. If I use &
reference, there's no copy, but now the variable is "exposed" to change.
If I pass an object by reference, there's no copy, but once again, the
properties are "exposed" and I still have the copy propagation problem
with multiple nested function calls. Would the best way be to pass an
object in the argument of the constructor to capture values for all
function within the new class?
 
Thanks in advance.
Cliff Hirsch
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20050714/f2640b22/attachment.html>


More information about the talk mailing list