Real properties in PHP
| From: | Marian Kostadinov | Date: | Thu, 25 Aug 2005 10:29:20 +0000 |
| Subject: | Real properties in PHP | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-18407@lists.php.net to get a copy of this message | ||
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