NYCPHP Meetup

NYPHP.org

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

Leila Lappin damovand at yahoo.com
Thu Jul 14 14:47:02 EDT 2005



--- Cliff Hirsch <cliff at pinestream.com> wrote:

> 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
> > _______________________________________________
> New York PHP Talk Mailing List
> AMP Technology
> Supporting Apache, MySQL and PHP
> http://lists.nyphp.org/mailman/listinfo/talk
> http://www.nyphp.org

The points that you are making are valid, but the
alternative to passing information as parameters is to
use global variables.  Using global variables negates
one of the major advantages of OO programming, that is
encapsulation.  In C++ we used be able to declare a
parameter as constant and prevent it from being
modified.  I&#8217;m not sure if
&#8216;const&#8217;ness is possible in PHP.


		
____________________________________________________
Start your day with Yahoo! - make it your home page 
http://www.yahoo.com/r/hs 
 



More information about the talk mailing list