Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:50839 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 42625 invoked from network); 3 Dec 2010 12:53:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Dec 2010 12:53:27 -0000 Authentication-Results: pb1.pair.com smtp.mail=president@basnetworks.net; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=president@basnetworks.net; sender-id=unknown; domainkeys=good Received-SPF: error (pb1.pair.com: domain basnetworks.net from 208.97.132.177 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.177 caiajhbdcbhh.dreamhost.com Linux 2.6 Received: from [208.97.132.177] ([208.97.132.177:34402] helo=homiemail-a17.g.dreamhost.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A6/50-40031-548E8FC4 for ; Fri, 03 Dec 2010 07:53:26 -0500 Received: from homiemail-a17.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a17.g.dreamhost.com (Postfix) with ESMTP id CA7DB7A805C; Fri, 3 Dec 2010 04:53:22 -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=Ui2tTZBcykZV/RNDw/6wN1D1ywc4LIwIbWaZGFEo6vy9f lOi6zZi5R137HnduqJ8nu9JXB6InoZhAlRIpFFHFJ6xKnCTwtnvr35J99DwVWThV Eyv2nQfeO80tYLWlq/P3th8+3NFPKX7XM1wtfYBVJhHpOR98INHGmdP9xHRdS4= 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=P7LRMXChBIiE+LC2sXqN8frPOtE=; b=qXVclEozhuRk btCYntFEd0w4nLXsxRGV3hshu/Z0sE5Hm+yFJuFcy2gtqmn7GhqPouXxAwxYvt1p xNDtuTBNs4KHE30hcaZieV8KheGnXwIVqLeEJlNYjMzJMe5KrmBF2oOtldzg8plx cFtpTP7qQreLXzMNmO9xJyWe1OIzAmk= Received: from webmail.basnetworks.net (caiajhbdcaib.dreamhost.com [208.97.132.81]) (Authenticated sender: president@basnetworks.net) by homiemail-a17.g.dreamhost.com (Postfix) with ESMTPA id 7C2097A8064; Fri, 3 Dec 2010 04:53:22 -0800 (PST) Received: from 70.28.48.126 (proxying for 70.28.48.126) (SquirrelMail authenticated user president@basnetworks.net) by webmail.basnetworks.net with HTTP; Fri, 3 Dec 2010 07:53:23 -0500 Message-ID: <4814e263cbd2b09767ca16908dd4ee01.squirrel@webmail.basnetworks.net> In-Reply-To: References: <003601cb8fd0$f6494e80$e2dbeb80$@com> <4CF3B855.5010406@sugarcrm.com> <003401cb8fee$1be39840$53aac8c0$@com> <2450924ae03481f5b1382a7f00e5743d.squirrel@webmail.basnetworks.net> <4CF50245.5020807@sugarcrm.com> <4CF5118B.2030300@sugarcrm.com> <1faa4c3db62771335db714507ac2adfa.squirrel@webmail.basnetworks.net> <4CF613EB.40200@sugarcrm.com> <8b46dd8e3e991cfe87550a9c55d9ecd8.squirrel@webmail.basnetworks.net> Date: Fri, 3 Dec 2010 07:53:23 -0500 To: RQuadling@googlemail.com Cc: "Eloy Bote Falcon" , "Stas Malyshev" , "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 > On 2 December 2010 13:51, wrote: >>> 2010/12/1 Richard Quadling >>> >>>> On 1 December 2010 09:22, Stas Malyshev >>>> wrote: >> ... >> >>> Why change the expected behavior of isset? If a property has not been >>> set >>> then isset must return false, and that includes $foo->name =3D NULL. >> >> >> Thats simple then, when isset is invoked, call the get method, and if = it >> returns null then isset() returns false, but otherwise returns true. >> =C2=A0That >> was likely just a small oversight on Richard's part. > > No, it was not an oversight. > > Calling the getter() in response to isset() will probably result in a > change to the value of the property. For a property, isset() can and > only be interested in the last value of the property, not the next > value. > > As I understand things, isset() performs 2 tests. First a check to see > if the variable exists and then to see if it has a value assigned. > > For a property, the first part of that equation is fairly simple - the > property has to exist or not. > > The second part though is not easy. A variable will not change value > in response to isset(), but, if isset() calls the getter(), then it > could and probably would. Calling isset() shouldn't alter anything. Agreed, isset should not alter anything. > Having isset() call the getter() and unset() call the setter() is fine > as long as the getter() and setter() know why they are being called. > > If the developer needs to supply the last value - their choice - then > this could be implemented by caching the last value in a local scope > static. Completely encapsulated. > > get($isset =3D false){ > static $lastValue; > > if (!$isset) { > // Generate the new value and assign it to $lastValue > } > > return $lastValue; > } The major issue I see here, is that a property should not be generating a value in an unpredictable way. In the example above, you indicate that the value could change just by calling the get method. While it is possible to write a property that does such a thing, this is completely incorrect and should not be actively supported by the language in any way= . The value of a property (as viewed from the outside of the class) should never, ever change solely by a call to a getter method. Basically what this means, is that two subsequent calls to a get method o= f a property should ALWAYS return the same value. I think this is the only scenario that we should care to support, and if the user is changing values in a getter method, then they need to understand that isset may no= t work as desired. If you need to generate and return a random or similar value, that should be done as a method. See the MSDN article "Choosing Between Properties and Methods" for more details: http://msdn.microsoft.com/en-us/library/ms229054.aspx Isset should be a direct reflection of the value that is/will be returned by the getter method. If you call isset() on a property, you are asking "if this property exists, and I access it, will I get a non-null value?". Not only that, an $isset parameter is ugly and cumbersome, and complicate= s a feature that is meant to simplify a programmers life. Having isset and unset methods alongside the get/set methods seems reasonable to me, for the situations that you do need to handle those operations explicitly, but I do not think an isset/unset implementation should be required in every case (meaning there must be a default way of handling that functionality), or else properties will be avoided by programmers due to being to complicated to create. - Dennis