Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:50769 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 63442 invoked from network); 1 Dec 2010 12:14:28 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Dec 2010 12:14:28 -0000 Authentication-Results: pb1.pair.com smtp.mail=rquadling@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rquadling@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.170 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: rquadling@gmail.com X-Host-Fingerprint: 209.85.216.170 mail-qy0-f170.google.com Received: from [209.85.216.170] ([209.85.216.170:39605] helo=mail-qy0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 27/10-62427-32C36FC4 for ; Wed, 01 Dec 2010 07:14:27 -0500 Received: by qyk10 with SMTP id 10so2383599qyk.8 for ; Wed, 01 Dec 2010 04:14:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:reply-to :in-reply-to:references:from:date:message-id:subject:to:cc :content-type:content-transfer-encoding; bh=VyHMi6NWumEUtc9l7LllsSTZ8MWSJWpmQ6f7aV4dnjQ=; b=CCclAI3CFrh843NzsppeOfidRkKggppzA1N6qX0cbhT2ZuTAOTSltx54lWBaIPpmbx fmBSLEiguAwPzkyPiFSGILxwmtK6ry2JMJHzffzRjBj0ydmrFLGf06qJyiokLrfnWas8 18WAfVBmPzuKg8UjI1C38kTdu6xsUtcOQqPe4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:reply-to:in-reply-to:references:from:date:message-id :subject:to:cc:content-type:content-transfer-encoding; b=gSnotIk9WpG1ki9mK0D6UM04/ljMNhFeFwz6bbkgZwbbwly67FtPWTqkacE9E84JJg 3qegrgaa/IeblczgS1H9xrbpATFMWjatj5D9WQtN18RseyMbLcr33tUrh6AsTVqbQSbn kfOF5j5gMeJSpC4OGslznOsqLKIWBE15hY+aQ= Received: by 10.229.95.211 with SMTP id e19mr7330443qcn.139.1291205664877; Wed, 01 Dec 2010 04:14:24 -0800 (PST) MIME-Version: 1.0 Received: by 10.229.100.130 with HTTP; Wed, 1 Dec 2010 04:14:03 -0800 (PST) Reply-To: RQuadling@googlemail.com 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> Date: Wed, 1 Dec 2010 12:14:03 +0000 Message-ID: To: Eloy Bote Falcon Cc: Stas Malyshev , "president@basnetworks.net" , "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] RFC: C-sharp style property get/set syntax for PHP From: rquadling@gmail.com (Richard Quadling) On 1 December 2010 10:23, Eloy Bote Falcon wrote: > 2010/12/1 Richard Quadling >> >> On 1 December 2010 09:22, Stas Malyshev wrote: >> > Hi! >> > >> >> Its not a matter of consistency - Properties, as a cross-language >> >> concept >> >> are not meant to work that way. =C2=A0You need to think of a property= as a >> >> set >> > >> > Meant by whom? Is there some law of universe that prevents us from >> > implementing the feature? >> > >> >> of two methods that just have a pretty syntax. =C2=A0Methods cannot b= e >> >> unset, >> >> and nor should properties be allowed to. =C2=A0isset() should simply = tell us >> >> whether a property with the specified name is part of the class or no= t. >> > >> > If you need methods, why not use methods? If you mimick object >> > properties, >> > however, it makes sense to make them work exactly like property, >> > otherwise >> > you have to explain why they don't work this way. >> > >> >> isset() in the way you suggest would just be confusing. =C2=A0It woul= d allow >> >> is >> >> to say that a property does not exist, when in fact it does exist. >> >> =C2=A0This >> >> is not logical. >> > >> > Sorry, from your answer I don't understand - what happens when you cal= l >> > isset($foo->property) and unset($foo->property)? >> >> If we think of properties as this new entity for the language (rather >> than somehow massaging existing entities to fit a new usage scenario), >> then >> >> isset($instance->property) will always return true for any defined >> property. Even if the getter would return null. This is new behaviour >> and can be easily documented. isset() for a property is more like >> method_exists() than isset() on a variable. >> With regard to unset($instance->property), from the manual ... >> >> "The behavior of unset() inside of a function can vary depending on >> what type of variable you are attempting to destroy." >> >> So, we already have differing behaviour based upon context. Attempting >> to destroy a property should through a non fatal error. >> >> One idea I had was to keep just the get/set property methods and add >> to them an additional parameter ... >> >> > public $seconds { >> =C2=A0 =C2=A0 =C2=A0 =C2=A0public set($value, $unset =3D False) { >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if ($unset) { >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0// unset() has been called on the property. >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0// In this instance $value will be Null. >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} else { >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0// set the property using the supplied $value. >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} >> =C2=A0 =C2=A0 =C2=A0 =C2=A0}, >> =C2=A0 =C2=A0 =C2=A0 =C2=A0public get($isset =3D False) { >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if ($isset) { >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0// isset() has been called on the property. >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0// If the value is a non-destructive calculation >> then maybe >> returning the comparison of the result of the calculation to null. >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} else { >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0// return the value for this property. >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} >> =C2=A0 =C2=A0 =C2=A0 =C2=A0} >> }; >> >> So, >> >> isset($instance->property) would call $instance->property->get(True); >> unset($instance->property) would call $instance->property->set(Null, >> True); >> >> This keeps just the 2 property methods. It still allows isset/unset >> and allows the developer the option of handling them. >> >> >> >> >> -- >> Richard Quadling >> Twitter : EE : Zend >> @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY >> >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: http://www.php.net/unsub.php >> > > > > Why change the=C2=A0expected behavior of isset? If a property has not bee= n set > then isset must return false, and that includes $foo->name =3D NULL. > > > Regards. > Say the property is write-only. How can isset() operate on that? If the property is read-only, how can you unset() it? If properties are abstractions to methods, then they don't serve a purpose. If properties are wrappers for locally cached values then they isset/unset is feasible. If properties are to "... provide the illusion of having normal class variables ..." ... then it is undefined if there is a real value held anywhere. You do not want isset() to have to get() the value of the property as the getter may be getting the data from (for example) a DB, SOAP request, etc. Getting the data is not as simple as just returning a local value. I think isset() and unset() for properties is different to that for variables. Either isset() and unset() generate errors when called on properties, or, with an amendment to the syntax, isset() and unset() are passed to the setter and getter (if they exist) to allow the developer of the property to decide what to return. --=20 Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY