Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:50693 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 43325 invoked from network); 29 Nov 2010 14:55:53 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Nov 2010 14:55:53 -0000 X-Host-Fingerprint: 65.19.76.48 unknown Date: Mon, 29 Nov 2010 09:55:52 -0500 Received: from [65.19.76.48] ([65.19.76.48:17402] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 12/20-42097-7FEB3FC4 for ; Mon, 29 Nov 2010 09:55:52 -0500 Message-ID: <12.20.42097.7FEB3FC4@pb1.pair.com> To: internals@lists.php.net References: User-Agent: slrn/pre1.0.0-18 (Linux) X-Posted-By: 65.19.76.48 Subject: Re: [PHP-DEV] RFC: C-sharp style property get/set syntax for PHP From: weierophinney@php.net (Matthew Weier O'Phinney) On 2010-11-29, Richard Quadling wrote: > On 28 November 2010 23:18, 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]. > > 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; > } > 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 | matthew@zend.com Zend Framework | http://framework.zend.com/ PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc