NYCPHP Meetup

NYPHP.org

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

David Mintz dmintz at davidmintz.org
Thu Jul 14 15:48:36 EDT 2005


On Thu, 14 Jul 2005, Flavio daCosta wrote:

> On 07/14/2005 12:08 PM, Cliff Hirsch wrote:
>  <snip />
> Variables:  If you have many that you are passing, I would encapsulate
> them in an object otherwise I would copy if I was concerned about
> tampering and reference if variable data is large.
>
> > 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.
>
> If you have accessors methods, you _should_ be able to protect against
> un-authorized changes, no?

We didn't ask him if he was in PHP 4 or 5.

In any case, doesn't PHP's copy-on-write behavior at least mitigate the
overhead problem? IOW you don't have to worry about pass-by-copy eating
too much memory unless the data is changed on the receiving end.

> <snip />
> You could also utilize the Singleton Design pattern.

... which is a piece of cake in PHP 5.


---
David Mintz
http://davidmintz.org/



More information about the talk mailing list