Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:50703 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 79249 invoked from network); 29 Nov 2010 18:18:57 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Nov 2010 18:18:57 -0000 Authentication-Results: pb1.pair.com header.from=larry@garfieldtech.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=larry@garfieldtech.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain garfieldtech.com from 76.96.30.32 cause and error) X-PHP-List-Original-Sender: larry@garfieldtech.com X-Host-Fingerprint: 76.96.30.32 qmta03.emeryville.ca.mail.comcast.net Received: from [76.96.30.32] ([76.96.30.32:51507] helo=qmta03.emeryville.ca.mail.comcast.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 26/E0-09015-09EE3FC4 for ; Mon, 29 Nov 2010 13:18:57 -0500 Received: from omta09.emeryville.ca.mail.comcast.net ([76.96.30.20]) by qmta03.emeryville.ca.mail.comcast.net with comcast id d3Pe1f00A0S2fkCA36Jtbm; Mon, 29 Nov 2010 18:18:53 +0000 Received: from earth.ufp ([98.220.236.211]) by omta09.emeryville.ca.mail.comcast.net with comcast id d6Js1f0094aLjBW8V6Jss4; Mon, 29 Nov 2010 18:18:53 +0000 Received: from localhost (localhost [127.0.0.1]) by earth.ufp (Postfix) with ESMTP id 0D3EFD7A51 for ; Mon, 29 Nov 2010 12:18:52 -0600 (CST) Received: from earth.ufp ([127.0.0.1]) by localhost (earth.ufp [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id G+dbaXDp0qs4 for ; Mon, 29 Nov 2010 12:18:51 -0600 (CST) Received: from garfield.ad.palantir.net (unknown [209.41.114.202]) by earth.ufp (Postfix) with ESMTPSA id CF2AAD79DA for ; Mon, 29 Nov 2010 12:18:51 -0600 (CST) Message-ID: <4CF3EE8A.4000405@garfieldtech.com> Date: Mon, 29 Nov 2010 12:18:50 -0600 User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.12) Gecko/20101027 Lightning/1.0b2 Thunderbird/3.1.6 MIME-Version: 1.0 To: internals@lists.php.net References: <4CF3B903.6000204@gmail.com> In-Reply-To: <4CF3B903.6000204@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] RFC: C-sharp style property get/set syntax for PHP From: larry@garfieldtech.com ("larry@garfieldtech.com") On 11/29/10 8:30 AM, Ángel González wrote: > What about allowing this syntax to attach the property to a variable? > > For instance: > > class TimePeriod > { > protected $seconds; > protected $minutes; > protected $hours; > > public property Seconds read $seconds write setSeconds; > public property Minutes read $seconds write setMinutes; > public property Hours read $seconds write setHours; > > public function setSeconds($seconds) > { > if ($seconds>= 0&& $seconds< 60) $this->seconds = $seconds; > } > > public function setMinutes($minutes) > { > if ($minutes>= 0&& $minutes< 60) $this->minutes = $minutes; > } > > public function setHours($hours) > { > if ($hours>= 0&& $hours< 24) $this->hours = $hours; > } > > } > > We only want to perform checks on write, so instead of writing the trivial > getters, the property is set to the variable itself. Child classes could > reattach it to a function if needing more control. Another advantage here would presumably be performance. If there's no getter defined then the engine could simply map $foo->bar to the class member directly (which is really fast) and not to a method, so there's no added overhead there. That still leaves the question of what happens with name collisions, though. ... and that makes me think that someone is sure to ask about runtime changes to the property structure sooner or later, as we keep asking about methods (and *sort of* have figured out with binding closures to objects, if that did actually get committed), so I'll go ahead and ask it now. :-) --Larry Garfield