Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:56805 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 6523 invoked from network); 6 Dec 2011 14:15:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Dec 2011 14:15:51 -0000 Authentication-Results: pb1.pair.com smtp.mail=krebs.seb@googlemail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=sebastian.krebs.berlin@googlemail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain googlemail.com designates 74.125.83.42 as permitted sender) X-PHP-List-Original-Sender: krebs.seb@googlemail.com X-Host-Fingerprint: 74.125.83.42 mail-ee0-f42.google.com Received: from [74.125.83.42] ([74.125.83.42:35082] helo=mail-ee0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 61/E1-30975-5932EDE4 for ; Tue, 06 Dec 2011 09:15:49 -0500 Received: by eekc13 with SMTP id c13so931014eek.29 for ; Tue, 06 Dec 2011 06:15:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=mime-version:sender:x-google-sender-delegation:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to :content-type; bh=HY1Y39MggwEtWj7CwGakP9LTM6axxAUxQPgzTPOCoac=; b=FnCo6Ymq5KNk4wlncLB/5bYGf1fTboxRd6Rf8PkRgQSA5Ny0OeCGnj7HDzepl3M5Ti E7IvpMZajzH9ZzrQoYkavJt0mJTzxsoqwYnxA//UlUoZ8wPjneVqT2DWZDZa2+dAbTAC gNdRKjxq47wDEPf9WtTu2c5CxVX7H+LY3DetU= MIME-Version: 1.0 Received: by 10.14.11.86 with SMTP id 62mr2586124eew.9.1323180945284; Tue, 06 Dec 2011 06:15:45 -0800 (PST) Sender: sebastian.krebs.berlin@googlemail.com X-Google-Sender-Delegation: sebastian.krebs.berlin@googlemail.com Received: by 10.204.184.207 with HTTP; Tue, 6 Dec 2011 06:15:45 -0800 (PST) In-Reply-To: References: <9570D903A3BECE4092E924C2985CE4853994C39F@MBX202.domain.local> Date: Tue, 6 Dec 2011 15:15:45 +0100 X-Google-Sender-Auth: C3uYaG4Ksqk9PoAFREsAHJYD3Wo Message-ID: To: internals@lists.php.net Content-Type: multipart/alternative; boundary=0016364c7acb379fe504b36d129a Subject: Re: [PHP-DEV] Re: Patch: getters/setters syntax Implementation From: krebs.seb@googlemail.com (Sebastian Krebs) --0016364c7acb379fe504b36d129a Content-Type: text/plain; charset=ISO-8859-1 Hi 2011/12/6 Rasmus Schultz > On Tue, Dec 6, 2011 at 3:45 AM, Christian Kaps >wrote: > > > Hi, > > > > I also find this syntax confusing and I think it has a huge WTF factor. > > > > Some thoughts about the syntax: > > - At the first glance, it isn't clear which visibility the getter or > > setter has > > - The extra indentation level makes the code more unreadable > > > > class Foo { > > > > /** > > * > > */ > > private $_bar; > > > > /** > > * > > */ > > public $bar{ > > > > /** > > * > > */ > > set { > > if ($bar) { > > $this->_bar = $bar * 12; > > } else { > > $this->_bar = 0 > > } > > } > > > > /** > > * > > */ > > private set { > > if ($this->_bar === null) { > > return 0; > > } > > > > return $this->_bar; > > } > > } > > > > /** > > * > > */ > > public function baz() { > > > > } > > } > > > > - What about type hints? > > > > I prefer a more AS3 like getter and setter syntax. > > http://help.adobe.com/en_US/**ActionScript/3.0_**ProgrammingAS3/** > > WS5b3ccc516d4fbf351e63e3d118a9**b90204-7f30.html#** > > WS5b3ccc516d4fbf351e63e3d118a9**b90204-7fcb< > http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7f30.html#WS5b3ccc516d4fbf351e63e3d118a9b90204-7fcb > > > > > > Have you read my previous mail http://news.php.net/php.**internals/56762 > > > . > > I think this syntax fits more to PHP because its similar to the already > > existing(magic) getter and setter syntax. > > > > What do you think? > > > > Christian > > > > I agree with all of those points - the extra indentation looks messy, and > yes, type hints are important. It does fit better with PHP in general. > > It would be nice to also have support for automatic backing fields in > addition though - so something simple like this: > > class BlogPost > { > private $_author; > > public get author() > { > return $this->_author; > } > > public set author(Person $value) > { > $this->_author = $value; > } > } > > Could be written like this: > > class BlogPost > { > public Person $author; > } > > Effectively, this shorthand syntax just gives you type-safe properties - > but it refactors nicely, since you can replace it with a full > implementation of a backing field at any point. > > (on second thought, I don't like the idea I suggested before - adding a > magical $value in accessors, similar to $this - it's confusing and it's > going to look like an undeclared local variable...) > Because it seems everybody throws in their preferred syntax :X class X { public $myProperty { /* public *inherited* */ set (AnotherClass $value) { // Value from "outside" return $value; // Set to property } private get (AnotherClass $value) { // Value from property (Maybe with typehint) return $value; // returns value to the caller } } /* = 'default value'; */; } * No _magic_ $value * Type-Hints * I think nearly no suprise, what happens here In my eyes the goal should be to _not_ separate a property from its accessor anymore, which disqualifies both of Rasmus Schultz suggestions. At least this is _the_ reason, why I want to see this RFC to be implemented. --0016364c7acb379fe504b36d129a--