Re: RFC: C-sharp style property get/set syntax for PHP

From: Date: Mon, 29 Nov 2010 14:55:56 +0000
Subject: Re: RFC: C-sharp style property get/set syntax for PHP
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-50694@lists.php.net to get a copy of this message
On 2010-11-29, Stas Malyshev <smalyshev@sugarcrm.com> wrote: > > Nice RFC, just an idea for an alternative syntax (added to the RFC as #2): > > > > property Hours { > > get { return $this->seconds / 3600; } > > set { $this->seconds = $value * 3600; } // The variable $value holds > > the incoming value to be "set" > > } > > > > class TimePeriod > > { > > private $seconds; > > > > public [Hours] $hours1; > > public {use Hours;} $hours2; > > } > > If you change "property" to "class" or "trait" and > "get" to "__get" you > need almost no new syntax :) Not really. With __get() and __set(), it's entirely likely that the class into which the trait is mixed in might override this already -- and not take into account the properties. That would be quite a brittle solution. -- Matthew Weier O'Phinney Project Lead | matthew@zend.com Zend Framework | http://framework.zend.com/ PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

« previous php.internals (#50694) next »