Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:50755 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 23905 invoked from network); 1 Dec 2010 07:59:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Dec 2010 07:59:45 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@stefan-marr.de; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=php@stefan-marr.de; sender-id=unknown Received-SPF: error (pb1.pair.com: domain stefan-marr.de from 85.88.12.247 cause and error) X-PHP-List-Original-Sender: php@stefan-marr.de X-Host-Fingerprint: 85.88.12.247 toolslave.net Received: from [85.88.12.247] ([85.88.12.247:40298] helo=uhweb12247.united-hoster.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A2/40-21713-F6006FC4 for ; Wed, 01 Dec 2010 02:59:44 -0500 Received: from cust194-138.dsl.as47377.net ([62.166.194.138] helo=[192.168.0.26]) by uhweb12247.united-hoster.com with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.69) (envelope-from ) id 1PNhb6-0005iP-G4; Wed, 01 Dec 2010 08:59:33 +0100 Mime-Version: 1.0 (Apple Message framework v1082) Content-Type: text/plain; charset=windows-1252 In-Reply-To: <1faa4c3db62771335db714507ac2adfa.squirrel@webmail.basnetworks.net> Date: Wed, 1 Dec 2010 08:59:18 +0100 Cc: "Stas Malyshev" , "internals@lists.php.net" Content-Transfer-Encoding: quoted-printable Message-ID: <6EC3583E-E7B7-431D-B544-82135A33E351@stefan-marr.de> 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> To: president@basnetworks.net X-Mailer: Apple Mail (2.1082) Subject: Re: [PHP-DEV] RFC: C-sharp style property get/set syntax for PHP From: php@stefan-marr.de (Stefan Marr) Hi: On 01 Dec 2010, at 01:31, president@basnetworks.net wrote: >>> That is true for PHP variables. isset is basically saying "does = this >>> variable exist", and unset is saying to get rid of it. >>=20 >> This is also true for object properties - see magic methods. I don't = see >> why you shouldn't be able to unset them - you can do that with = regular >> properties... So what you imagine would happen if you call >> unset($foo->property) or isset($foo->property)? >=20 > Its not a matter of consistency - Properties, as a cross-language = concept > are not meant to work that way. =20 I tend to disagree. The need to be consistent inside of PHP has precedence over being = consistent with other languages. > You need to think of a property as a set > of two methods that just have a pretty syntax. Methods cannot be = unset, > and nor should properties be allowed to. isset() should simply tell = us > whether a property with the specified name is part of the class or = not. I think, it really is the other way around. Properties are meant to give the programmer the illusion that she is = just having a field. That is abstraction. She does not care about implementation details. And that is the power of properties. isset() and unset() are perfectly fine in that context. And I do not see a problem to provide the standard semantics for them = automatically, and let the programmer add isset/unset methods to the = property as needed in exactly the same style as get/set. There is a good usecase for asking whether a property has been set, for = instance to verify initialization. And, of course unset has also a useful meaning. It is about the value, = and even so there are methods around a value, properties are meant to be = values. There are definitely use-cases where that does not hold, but that is = application specific. > isset() in the way you suggest would just be confusing. It would = allow is > to say that a property does not exist, when in fact it does exist. = This > is not logical. =46rom the docu: isset =97 Determine if a variable is set and is not = NULL There is nothing confusing about isset($this->Hours) =3D=3D FALSE in = your example if isset($this->seconds) =3D=3D FALSE. Best regards Stefan --=20 Stefan Marr Software Languages Lab Vrije Universiteit Brussel Pleinlaan 2 / B-1050 Brussels / Belgium http://soft.vub.ac.be/~smarr Phone: +32 2 629 2974 Fax: +32 2 629 3525