NYCPHP Meetup

NYPHP.org

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

Cliff Hirsch cliff at pinestream.com
Thu Jul 14 16:27:31 EDT 2005


Thanks David:

I am using PHP 5 and should have read this chapter more completely!

PHP 5 Object, Patterns, and Practice: Page 141, "The Singleton Pattern,
The global variable is one of the great bugbears of OOP..." More bedtime
reading...

Plus for ready only, copy-on-write behavior would eliminate the overhead
problem.

Since we have that licked, another question. I have not been able to
find canned functions for turning a MySQL DB linked list (id,
description, parent id) into an array tree. Managing categories seems
like such a popular task, that I'm surprised that I have not found
standard functions for the front-end, back-end admin. Etc. Has anyone
tried PEAR HTML_TreeMenu or Tree (which at 0.2.4 (beta) released on
2003-03-17 does not seem very active) to do this?

-----Original Message-----
From: talk-bounces at lists.nyphp.org [mailto:talk-bounces at lists.nyphp.org]
On Behalf Of David Mintz
Sent: Thursday, July 14, 2005 3:49 PM
To: NYPHP Talk
Subject: Re: [nycphp-talk] Optimal Object, property, variable passing
strategybetween classes


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




More information about the talk mailing list