Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:50681 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 77707 invoked from network); 29 Nov 2010 07:48:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Nov 2010 07:48:50 -0000 Authentication-Results: pb1.pair.com smtp.mail=christian.kaps@mohiva.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=christian.kaps@mohiva.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mohiva.com from 178.63.228.54 cause and error) X-PHP-List-Original-Sender: christian.kaps@mohiva.com X-Host-Fingerprint: 178.63.228.54 elvis.mohiva.com Linux 2.6 Received: from [178.63.228.54] ([178.63.228.54:49073] helo=elvis.mohiva.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 73/20-10413-0EA53FC4 for ; Mon, 29 Nov 2010 02:48:50 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by elvis.mohiva.com (Postfix) with ESMTP id E64B31D247D5; Mon, 29 Nov 2010 08:48:45 +0100 (CET) X-Virus-Scanned: amavisd-new at mohiva.com Received: from elvis.mohiva.com ([127.0.0.1]) by localhost (elvis.mohiva.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id beQ4XA7FiCNm; Mon, 29 Nov 2010 08:48:44 +0100 (CET) Received: from roundcube.mohiva.com (elvis.mohiva.com [178.63.228.54]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: christian.kaps@mohiva.com) by elvis.mohiva.com (Postfix) with ESMTPSA id C5D381D247D4; Mon, 29 Nov 2010 08:48:44 +0100 (CET) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Date: Mon, 29 Nov 2010 08:48:44 +0100 To: Cc: In-Reply-To: References: Message-ID: <1435df535dae7a2badf6faf09a6b54dc@mohiva.com> X-Sender: christian.kaps@mohiva.com User-Agent: Roundcube Webmail/0.4.2 Subject: Re: [PHP-DEV] RFC: C-sharp style property get/set syntax for PHP From: christian.kaps@mohiva.com (Christian Kaps) Hi, I like the idea of the property get/set syntax, but in my opinion it doesn't figure with PHP's syntax, because it breaks the readability. The problem for me is the nesting of the inner set and get. How do you document these syntax. /** * */ public $name { /** * */ get { return $this->name; } /** * */ set { $this->name = htmlentities($value); $this->name = strip_tags($this->name); } }; What I also miss is the lack of type hinting. As I see it, it isn't possible with this syntax. I would prefer the syntax from ActionScript. This is more like the normal PHP function syntax with an additional set or get keyword. /** * */ public function set name(string $name) { $this->name = htmlentities($name); $this->name = strip_tags($this->name); } /** * */ public function get name($name) { return $this->name; } Greetings, Christian On Sun, 28 Nov 2010 18:18:40 -0500, president@basnetworks.net wrote: > Hello, > > This is my first time using a mailing list, so please bear with me. > > Some time back I suggested that PHP should have a property get/set > syntax > similar to that of Microsoft's C# language. One of the PHP > developers > suggested that if I were serious about it, I should write an RFC. I > have > done just that, and I would now like to present my RFC to everyone > here in > internals, in order to start a discussion on the topic. > > The RFC: > > Many modern languages have a special syntax for writing get/set > method > pairs. All that PHP currently supports is __get and __set, which > while > great for writing generic get/set methods is nearly useless when it > comes > to individual properties. Our only other choice is the age old > process of > writing custom class methods to make our get/set methods. Not only > does > this lack any kind of uniformity, but it also complicates the syntax > ($foo->getBar() and $foo->setBar('baz') instead of $foo->bar and > $foo->bar='baz'). I believe that if PHP is going embrace modern > object-oriented design, including encapsulation, than it needs a > modern > solution to property getters and setters. > > I wont add much more here, but rather let the RFC itself do the > talking. > It is fairly well fleshed out, and should explain everything clearly > enough. > > Link to the RFC: > http://wiki.php.net/rfc/propertygetsetsyntax > > Thanks, > Dennis Robinson