Re: Real properties in PHP
| From: | Marian Kostadinov | Date: | Thu, 25 Aug 2005 10:51:50 +0000 |
| Subject: | Re: Real properties in PHP | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-18409@lists.php.net to get a copy of this message | ||
On 8/25/05, Christian Schneider <cschneid@cschneid.com> wrote:
> Marian Kostadinov wrote:
> > public getter fullName { // may also have ()
> > return "{$this->firstName} {$this->lastName}";
> > }
> >
> > public setter fullName ($value) { // may also not have ($value) but
> > a special var.
> > list ($this->firstName, $this->lastName) = explode (' ', $value, 2);
> > }
>
> This can be easily done with
>
> function __get($name)
> {
> $get = "get_$name";
>
> return $this->$get();
> }
>
> function __set($name, $value)
> {
> $set = "set_$name";
>
> $this->$set($value);
> }
>
> in your base class (the function names are then get_fullName/set_fullName..
>
> - Chris
>
I know this solutions but it does not solve the property visibility
issues and good overloading rules like in common methods. Let's say
you have about 6-7 suche proterties which you expect to overload and
some of the are private e.t.c