On 2010-11-29, Richard Quadling <rquadl...@gmail.com> wrote:
> 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;
>     }

<snip>

> 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.

I prefer this as well. It often aids readability to use fluent
interfaces when performing operations that are simply changing state,
and being able to call the setters directly would make that possible:

$time->setHours(3)
     ->setMinutes(17)
     ->setSeconds(34);

Additionally, this seems like a very natural fit with traits, making it
possible to really succinctly define behavior to mix in with classes.

-- 
Matthew Weier O'Phinney
Project Lead            | matt...@zend.com
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to