Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:50708 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 10136 invoked from network); 29 Nov 2010 20:48:00 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Nov 2010 20:48:00 -0000 Authentication-Results: pb1.pair.com header.from=dubois.benjamin@me.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=dubois.benjamin@me.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain me.com designates 17.148.16.104 as permitted sender) X-PHP-List-Original-Sender: dubois.benjamin@me.com X-Host-Fingerprint: 17.148.16.104 asmtpout029.mac.com Solaris 10 1203 Received: from [17.148.16.104] ([17.148.16.104:63406] helo=asmtpout029.mac.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 59/50-07888-F7114FC4 for ; Mon, 29 Nov 2010 15:48:00 -0500 MIME-version: 1.0 Content-type: text/plain; charset=iso-8859-1 Received: from [10.0.1.2] (85-170-208-8.rev.numericable.fr [85.170.208.8]) by asmtp029.mac.com (Sun Java(tm) System Messaging Server 6.3-7.04 (built Sep 26 2008; 64bit)) with ESMTPSA id <0LCN00HU9Z3FWZ40@asmtp029.mac.com> for internals@lists.php.net; Mon, 29 Nov 2010 12:47:44 -0800 (PST) X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 ipscore=0 suspectscore=4 phishscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx engine=6.0.2-1010190000 definitions=main-1011290140 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.2.15,1.0.148,0.0.0000 definitions=2010-11-29_11:2010-11-29,2010-11-29,1970-01-01 signatures=0 In-reply-to: Date: Mon, 29 Nov 2010 21:47:39 +0100 Content-transfer-encoding: quoted-printable Message-ID: References: <4CF3B903.6000204@gmail.com> To: internals@lists.php.net X-Mailer: Apple Mail (2.1082) Subject: Re: [PHP-DEV] RFC: C-sharp style property get/set syntax for PHP From: dubois.benjamin@me.com (Benjamin Dubois) Hi ! This is my first email here (I'm just a PHP user, with only very basic C = skills, but I'm working on it), and I would love to contribute to this = project. I have been working with Objective-c lately, and it has a very flexible = and short way to deal with properties, which could look like this in PHP = :=20 2010/11/29 =C1ngel Gonz=E1lez : >> Richard Quadling wrote: >> setMilliseconds() should have $value as parameter instead of a magic = name. >>=20 >> What about allowing this syntax to attach the property to a variable? >>=20 >> For instance: >>=20 >> > class TimePeriod >> { >> protected $seconds; >> protected $minutes; >> protected $hours; >>=20 >> public property Seconds read $seconds write setSeconds; >> public property Minutes read $seconds write setMinutes; >> public property Hours read $seconds write setHours; >>=20 >> public function setSeconds($seconds) >> { >> if ($seconds >=3D 0 && $seconds < 60) $this->seconds =3D = $seconds; >> } >>=20 >> public function setMinutes($minutes) >> { >> if ($minutes >=3D 0 && $minutes < 60) $this->minutes =3D = $minutes; >> } >>=20 >> public function setHours($hours) >> { >> if ($hours >=3D 0 && $hours < 24) $this->hours =3D $hours; >> } >>=20 >> } >>=20 >> 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. >=20 > Ouch. I messed up on the example code. Completely forget that there > was a parameter to process... >=20 > As for reading $seconds directly ... >=20 > Well. >=20 > If you think of the element that follows read as $this->xxxx, then if > the parser can handle both ... >=20 > read $seconds > read getSeconds >=20 > then yes for both. >=20 > If not, then I'd guess that the getSeconds version should be the one > we use as the value may not actually exist without some processing. >=20 > Richard. >=20 > --=20 > Richard Quadling > Twitter : EE : Zend > @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY >=20 > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >=20