Thread: Re: [PHP] Info into Class

Re: [PHP] Info into Class

From
Dan Ostrowski
Date:
Absolutely. I can't stress this enough, as it's one of the major rules of
OO and has saved my arse several times.  Even WITHIN the class, I use the
setX() methods over modifying $this->X = whatever, because you can
"intercept" those calls later on with minimal code change.

dan

On Tue, 3 Sep 2002 08:45:08 -0700
"Greg Martin" <gregm@3dcomputer.com> wrote:

> The thing about PHP classes is that there are not many rules.  It is
> usually suggested, as a matter of good practice to use get and set
> functions for your variables in classes in any language.  A lot of
> people my think this is a bunch of extra work, but let's say you are
> keeping track of customers, and you are storing their phone number.  If
> you write get/set functions for that variable, if later on you decide
> that you really need to be validating the phone numbers format, or
> getting a particular format out of the class you can easily add that
> code right in the get/set function and then that process only has to
> happen in one place, keeping your code nice and clean.
>
> greg
>
> -----Original Message-----
> From: Gerard Samuel [mailto:gsam@trini0.org]
> Sent: Tuesday, September 03, 2002 6:45 AM
> To: php-gen
> Subject: [PHP] Info into Class
>
>
> Are there any rules as to how information from outside a class can be
> moved into it.
> What Ive been doing so far is
> 1.  Through the constructor
> 2.  defining a constant
> 3.  Create a method whose sole purpose is to move data from the outside
> into the class.
>      i.e.
> <?php
> class foo ()
> {
> ......
>     function outside_data($bar)
>     {
>         $this->bar = $bar;
>     }
> ......
> }
>
> // class constructor here
> .......
> $class->outside_data($php);
>
> ?>
>
> --
> Gerard Samuel
> http://www.trini0.org:81/
> http://dev.trini0.org:81/
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php