On 28 November 2010 23:18, <presid...@basnetworks.net> wrote: > Link to the RFC: > http://wiki.php.net/rfc/propertygetsetsyntax > > Thanks, > Dennis Robinson
I'd really like this feature to be part of PHP. I don't particularly like the use of what looks like a closure for the set/get. I used to code in Delphi and I always like the way in which their properties were defined. Essentially, the setter and getter are normal methods which are cherry picked for a property [1]. <?php class TimePeriod { protected $seconds; public property Hours read getHours write setHours; protected function getHours() { return $this->seconds / 3600; } protected function setHours() { $this->seconds = $value * 3600; } // This property is read-only public property Minutes read getMinutes; protected function getMinutes() { return $this->seconds / 60; } public property Milliseconds read getMilliseconds write setMilliseconds; public function getMilliseconds() { // This method is public return $this->seconds * 60; } protected function setMilliseconds() { // This method is protected $this->seconds = $value * 3600; } } For me, the advantage here is that I can independently the methods from the property. If I want to force a subclass to implement a setter/getter, then I can abstract the function in the base class. Sure, some may say that I should be using an interface. I disagree as I probably don't want the methods to be public. Protected or even private and/or final. The classic example is one of shapes. Every shape has a public $area property, but the value would be provided by an abstract protected TShape::getArea(); method. I can also finalise them, so, for example, a triangle shape could have a final protected getArea() method and all sub classes of triangles (scalene, isosceles, equilateral) would not implement their own getArea() method. The downside is certainly that the code is more verbose than I would guess many people would like. Regards, Richard. [1] http://www.delphibasics.co.uk/RTL.asp?Name=Property -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php