Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:50751 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 70739 invoked from network); 1 Dec 2010 00:39:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Dec 2010 00:39:46 -0000 Authentication-Results: pb1.pair.com header.from=president@basnetworks.net; sender-id=unknown; domainkeys=good Authentication-Results: pb1.pair.com smtp.mail=president@basnetworks.net; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain basnetworks.net from 208.97.132.119 cause and error) DomainKey-Status: good X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: president@basnetworks.net X-Host-Fingerprint: 208.97.132.119 caiajhbdcbbj.dreamhost.com Windows 98 (1) Received: from [208.97.132.119] ([208.97.132.119:33264] helo=homiemail-a75.g.dreamhost.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 21/23-53511-05995FC4 for ; Tue, 30 Nov 2010 19:39:45 -0500 Received: from homiemail-a75.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a75.g.dreamhost.com (Postfix) with ESMTP id 15BE25EC063; Tue, 30 Nov 2010 16:39:42 -0800 (PST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=basnetworks.net; h=message-id :in-reply-to:references:date:subject:from:to:cc:mime-version :content-type:content-transfer-encoding; q=dns; s= basnetworks.net; b=xhcb9jq8NeVQbaSR04me2tQyoV7J1C7yR//BB76WpzKS0 v/RRojiOKYdqmHrVoJMuNvZmZfHpLmZONpyKEL9HTRVQXRnNkpzZK+trKORNdGpu 9RhbHDB+jF9jbOHYHvRBdEHeWScF6gJLYWjZBX8/nxnwAGTN2x6p2ztWPn/tSM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=basnetworks.net; h= message-id:in-reply-to:references:date:subject:from:to:cc :mime-version:content-type:content-transfer-encoding; s= basnetworks.net; bh=LE+4FRymxWmNIL8EYWQtrxkGyvA=; b=rJHlBV9WBLvT 26iDmIQOi5+GAl3G1bVkZzu627p/mRZ5YuMpbZS63xbA5SBRJlCTul0wNYdTcLF/ JEhh59EUcUqo/V/+F9CydALw9yUIs8/mECewhBAum1/bN1Zp56byoMiXGC8CRG2U uiy049Rwy/ZAwemYlAuu3FOL8xDv6lo= Received: from webmail.basnetworks.net (caiajhbdcagg.dreamhost.com [208.97.132.66]) (Authenticated sender: president@basnetworks.net) by homiemail-a75.g.dreamhost.com (Postfix) with ESMTPA id 86C865EC060; Tue, 30 Nov 2010 16:39:41 -0800 (PST) Received: from 69.165.140.136 (proxying for 69.165.140.136) (SquirrelMail authenticated user president@basnetworks.net) by webmail.basnetworks.net with HTTP; Tue, 30 Nov 2010 19:39:42 -0500 Message-ID: <7251c0fce39578c68ccc642410b1311a.squirrel@webmail.basnetworks.net> In-Reply-To: References: <073c59f255a348e9684fb4875490b23f.squirrel@webmail.basnetworks.net> Date: Tue, 30 Nov 2010 19:39:42 -0500 To: RQuadling@googlemail.com Cc: president@basnetworks.net, internals@lists.php.net User-Agent: SquirrelMail/1.4.21 MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] RFC: C-sharp style property get/set syntax for PHP From: president@basnetworks.net > Thanks for your reply. > > Fundamentally, a big +1 from my little voice on having setters/getters = in > PHP. > > > The issue of documentation is probably that the documentation tools > would have to adapt. As things stand PHPDoc doesn't support > namespaces, so setters/getters would just be added to the WIBNI list. Here is a reply I wrote to Christan Kaps on the same subject: > Christan Wrote: > > 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. T= he > 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 =3D htmlentities($value); > $this->name =3D strip_tags($this->name); > } > }; Typically you only document the property as a whole, and not the individual get and set method. Since they are a pair, there should be no reason to document them separately. If the get method is doing something totally different from the set, then they should not be paired, as that i= s confusing. In C# you would typically see documentation like this: Only a get method: /// Gets the duration of the Timespan in seconds. public int Seconds { get; } Only a set method: /// Sets the duration of the Timespan in seconds. public int Seconds { set; } Both a get and set method: /// Gets/sets the duration of the Timespan in seconds. public int Seconds { get; set; } > With regard to the value supplied to the set method, would it make > more sense for PHP to be ... > > set($value) { $this->seconds =3D $value * 3600; } > > or > > set { $this->seconds =3D __SETVALUE__ * 3600; } > > Having $value without a clear indication of where it comes from > doesn't read quite right. > > $value is way to generic to be magically created. __SETVALUE__ (or > __SOMETHINGELSE__) is clear in this regard. That is a good point. In C# it is simple the variable "value", which is where I got $value from. Rather magicy, yes. A constant could work, and would be more in line with PHP's magic constants. Just a quick question though, can a constant store all of the same data variable can? What about a reference? Also, sometimes users in C# like to modify the contents of the "value" variable before using it for something else. If it were a constant this would not be possible, you would have to define a new variable, then copy the value from the constant, which seems unnecessarily cumbersome. - Dennis