Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:50851 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 84780 invoked from network); 5 Dec 2010 16:47:32 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Dec 2010 16:47:32 -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.74 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.74 caiajhbdcahe.dreamhost.com Linux 2.6 Received: from [208.97.132.74] ([208.97.132.74:60236] helo=homiemail-a23.g.dreamhost.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0B/58-19822-222CBFC4 for ; Sun, 05 Dec 2010 11:47:31 -0500 Received: from homiemail-a23.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a23.g.dreamhost.com (Postfix) with ESMTP id 359D54B0063; Sun, 5 Dec 2010 08:47:28 -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=ENBlkp/6QXPKV7UN6l2sCgtJcOEM4DHvOGMSqyqmIJmYA /jCTJ/CxSbl0GnDNwjna5lChwcu5sO9Pw4Cy4rP5RcipufB31H26NzueRjOujwbh uymjsj0sfKms+sb7jg/gu5iTeXX5drw+WdZOC25qYEZHD7qRd+HMq029aB8H+Y= 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=ZHgQURqvT0Dzlaok98Wd+svHOew=; b=hsZTWYWkTVIl PWG/yGXSMuzX1RITM73JYEZQfByfdZLveX+Y3RjeC697T8q7X8bxBAQPE+pbgjpG OeZR5tQaqroS8Hb3hC+azDW/vSVO/nCeufCjkUibw5tH31zF6z81m7DG9RDaMl47 ENSXAVUizh71uBJFnbqaiLGklse0jrs= Received: from webmail.basnetworks.net (caiajhbdcbbj.dreamhost.com [208.97.132.119]) (Authenticated sender: president@basnetworks.net) by homiemail-a23.g.dreamhost.com (Postfix) with ESMTPA id DC2CD4B0060; Sun, 5 Dec 2010 08:47:27 -0800 (PST) Received: from 69.157.54.252 (proxying for 69.157.54.252) (SquirrelMail authenticated user president@basnetworks.net) by webmail.basnetworks.net with HTTP; Sun, 5 Dec 2010 11:47:28 -0500 Message-ID: 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> <4814e263cbd2b09767ca16908dd4ee01.squirrel@webmail.basnetworks.net> Date: Sun, 5 Dec 2010 11:47:28 -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 > In a multi-user system, any of these values could be different from > one moment to the next. > > class Account{ > public property $AvailableBalance{ > get{ > return $this->CreditLimit - ($this->AccountBalance - $this->OnOrder)= ; > } > } > } > > This hides the mechanics away and tells any user that the account for > this order has a realtime $CreditLimit, $AccountBalance, $OnOrder and > an accurate $AvailableBalance. At the beginning and end of the order > entry and maybe as each line is being entered, the AvailableBalance is > accessed to see if it the current order can be met financially. > > The Account's properties are all read-only in this scenario (I'd have > 2 Account classes, one for the Sales Ledger and a subclass for > everywhere else. The ability to essentially remove the setter() in a > subclass would turn a read/write property into a readonly property). > > > So, based upon this fairly simple scenario, isset() would clearly > alter the value of the account's properties if it had to call the > getter()s. I am not sure I follow, your example is complex to read and understand.=20 Loading the value of a property from a cache, or from a DB is fine, although I see no benefit of doing it multiple times in the same page load. Besides, I think you mis-interpreted what I was saying. Please read agai= n: > 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 w= ay. > The value of a property (as viewed from the outside of the class) shou= ld > never, ever change solely by a call to a getter method. Specifically the part "a property should not be generating a value in an unpredictable way." is what I was talking about. I think you took thing= s I wrote after that out of context. Changing the value that comes out a property dynamically is fine, that is what they are for, however, it should be predictable. A random value is not predictable, and should not be in a getter. If I have an object called "PiggyBank", with the property "dollars" set t= o 5, "dimes" set to 4 and "nickles" set to 1, then I get the contents of th= e property "Total", I can predict it will give me the value 5.45. That is what properties are really for. If you are loading a value from a database several times on the same page load, it could be modified by some other process, and therefore that is not very predictable. That should likely be a regular method (CheckDBValue() or some such). > You say "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.". > > How are you going to stop me from writing code that DOES generate a > new and appropriate value in response to a getter() request. First, as noted above, this was taken out of context. Secondly, I never said it should be prevented, but rather not supported. Those are very different concepts. > Surely that's the exact job of a getter()? To generate and supply a > potentially new and accurate value. Not to supply some pre-hashed > value which is accessible via __get() or by directly accessing a > public variable (as seen in the EmployeeRecord on the MSDN link you > gave - completely pointless). Yes, that is one of the many jobs as a getter. Just for the record, passing a value purely through a property without changing it is far from pointless. First of all, it allows you to independently create get or set methods, creating implicit readonly or writeonly properties. By defining a property you can also set each get/set methods visibility separately, or set either one final or abstract. In the case of creating a property that does not do any of this special functionality, and just passes through a value, there are still arguments for it. For one, it creates code uniformity. If 90% of the rest of a classes public members are properties, then converting the last few publi= c variables to properties makes sense and is easier to read. Additionally, if you define all public members as properties right off the bat, it is easy to add additional functionality and validation checks as you go, instead of stopping to convert the member to a property. These scenarios are definitely supported in C#. For example, in more recent versions of C#, you can now create a property like this: public string MyString { get; set } That right there, when compiled, is the exact same thing as this: public class MyClass { private string someString; public string MyString { get { return someString; } set { someString =3D value; } } } So as you can see, this scenario is heavily supported in C#, and is considered good practice. Creating all public members as properties give= s you the most flexibility when creating classes and maintaining them in th= e future. > The response to isset/unset can only sensibly be handed by the > designer of the property. Either as additional isset()/unset() > functions in the property, or as a flag to the get()/set() functions I disagree, isset/unset should have a default functionality and you shoul= d not be required to implement them unless you have a special reason to do so. Their definitions would be the exact same code 99% of the time anyway, so it would only provide to be an annoyance to have to implement them every time. - Dennis