Re: Real properties in PHP
| From: | Ron Korving | Date: | Wed, 31 Aug 2005 14:50:30 +0000 |
| Subject: | Re: Real properties in PHP | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-18609@lists.php.net to get a copy of this message | ||
I very much like your idea and syntax. I come from a Delphi background (when
it comes to properties) and I must say I like your solution. It's easy and
effective. Yes, it can be done with __set() and __get(), but it sure is
uglier when you have a wide and constant range of properties.
+1 (with 0 karma anyway).
Ron
"Marian Kostadinov" <manchokapitancho@gmail.com> wrote in message
news:bec76cf9050825032978cd308d@mail.gmail.com...
I wrote about real properies a few days ago but no one seems to be
interested in it.
I think that it would be nice to have real properties present in PHP. I
mean properties like those in C# but a little more flexible by allowing
getter and setter to have different visibility. See sample code below:
Sample code:
---------------
class person {
public $firstName, $lastName;
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);
}
}
$p = new person;
$p->fullName = "Foo bar";
echo $p->firstName . "\n";
echo $p->lastName . "\n";
echo $p->fullName . "\n";
Sample result:
----------------
Foo
bar
Foo bar