Hi,
I like the idea of the property get/set syntax, but in my opinion it
doesn't figure with PHP's syntax, because it breaks the readability. The
problem for me is the nesting of the inner set and get. How do you
document these syntax.
/**
*
*/
public $name {
/**
*
*/
get {
return $this->name;
}
/**
*
*/
set {
$this->name = htmlentities($value);
$this->name = strip_tags($this->name);
}
};
What I also miss is the lack of type hinting. As I see it, it isn't
possible with this syntax.
I would prefer the syntax from ActionScript. This is more like the
normal PHP function syntax with an additional set or get keyword.
/**
*
*/
public function set name(string $name) {
$this->name = htmlentities($name);
$this->name = strip_tags($this->name);
}
/**
*
*/
public function get name($name) {
return $this->name;
}
Greetings,
Christian
On Sun, 28 Nov 2010 18:18:40 -0500, presid...@basnetworks.net wrote:
Hello,
This is my first time using a mailing list, so please bear with me.
Some time back I suggested that PHP should have a property get/set
syntax
similar to that of Microsoft's C# language. One of the PHP
developers
suggested that if I were serious about it, I should write an RFC. I
have
done just that, and I would now like to present my RFC to everyone
here in
internals, in order to start a discussion on the topic.
The RFC:
Many modern languages have a special syntax for writing get/set
method
pairs. All that PHP currently supports is __get and __set, which
while
great for writing generic get/set methods is nearly useless when it
comes
to individual properties. Our only other choice is the age old
process of
writing custom class methods to make our get/set methods. Not only
does
this lack any kind of uniformity, but it also complicates the syntax
($foo->getBar() and $foo->setBar('baz') instead of $foo->bar and
$foo->bar='baz'). I believe that if PHP is going embrace modern
object-oriented design, including encapsulation, than it needs a
modern
solution to property getters and setters.
I wont add much more here, but rather let the RFC itself do the
talking.
It is fairly well fleshed out, and should explain everything clearly
enough.
Link to the RFC:
http://wiki.php.net/rfc/propertygetsetsyntax
Thanks,
Dennis Robinson
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php