NYCPHP Meetup

NYPHP.org

[nycphp-talk] Accessing Properties in PHP OOP

Scott Mattocks scott at crisscott.com
Thu Aug 26 10:09:21 EDT 2004


randal rust wrote:

> OK, that makes sense. But how is it different, or better than what I'm 
> doing now? On the surface, it appears that my current method may break 
> in PHP 5. I'm currently using different versions of PHP 4.2+, but want 
> to code it so that I won't have too much to change whenever I bump up to 5.
It is better because this allows each instance of client to have its own 
instance of display and validator. It will let each client display 
things they way they want without interfering with other client objects.

You method uses only one instance of the display and validator classes. 
If you had two instances of the client class you can't be sure that 
values display has because you don't know which client has modified it last.
> 
> FYI, $conn is a call to my database connection.
> 
> And, just so I make sure I understand, each of my individual methods 
> within client, which need to access class_display and class_validator, 
> would need to include...
> 
> $this->display =& new Display
> $this->validator =& new Validator
> 
> ...right?
> 
No! The constructor (function Client()) is the only one that needs to do 
this. It is setting the members of the class so that they will be 
alvailable in _all_ methods of the class. Once $this->display is 
assigned you can use it in any method of the class.

Scott Mattocks



More information about the talk mailing list