Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:50754 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 89800 invoked from network); 1 Dec 2010 03:02:19 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Dec 2010 03:02:19 -0000 Authentication-Results: pb1.pair.com smtp.mail=davey@php.net; spf=unknown; sender-id=unknown Authentication-Results: pb1.pair.com header.from=davey@php.net; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain php.net does not designate 206.46.173.7 as permitted sender) X-PHP-List-Original-Sender: davey@php.net X-Host-Fingerprint: 206.46.173.7 vms173007pub.verizon.net Solaris 10 1203 Received: from [206.46.173.7] ([206.46.173.7:47168] helo=vms173007pub.verizon.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2A/F5-53511-ABAB5FC4 for ; Tue, 30 Nov 2010 22:02:19 -0500 Received: from bastet-2.home ([unknown] [72.91.196.169]) by vms173007.mailsrvcs.net (Sun Java(tm) System Messaging Server 7u2-7.02 32bit (built Apr 16 2009)) with ESMTPA id <0LCQ00A2IB3M71X2@vms173007.mailsrvcs.net> for internals@lists.php.net; Tue, 30 Nov 2010 21:02:16 -0600 (CST) MIME-version: 1.0 (Apple Message framework v1081) Content-type: text/plain; charset=us-ascii In-reply-to: <1faa4c3db62771335db714507ac2adfa.squirrel@webmail.basnetworks.net> Date: Tue, 30 Nov 2010 22:02:10 -0500 Cc: "Stas Malyshev" , "internals@lists.php.net" Content-transfer-encoding: quoted-printable Message-ID: <4CA4675C-62DB-4808-ACB0-0F91391A81CA@php.net> 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.1081) Subject: Re: [PHP-DEV] RFC: C-sharp style property get/set syntax for PHP From: davey@php.net (Davey Shafik) Object properties (or members, classic ->var, not this proposed syntax) = CURRENTLY, work this way: php -r 'class foo { public $bar; } $foo =3D new foo(); = var_dump(isset($foo->bar));' bool(false) This is because you are confusing PHP's isset() with a = property_exists(). Is set. Is the variable (or member/property) set to a value? In this case, both isset() and unset() work with the property get/set = you are proposing. Imagine: $results =3D $db->query('SELECT SQL_CALC_FOUND_ROWS * FROM some_table = WHERE foo =3D 'bar'); if (isset($results->count)) { foreach ($results->getResult() as $result) { // Do something } } where isset() would hit: protected property count { isset { $result =3D $this->execute('SELECT FOUND_ROWS()'); $this->count =3D $result->getColumn(); if ($this->count =3D=3D 0) { return false; } return false; } } Not an ideal example, but it gives you an IDEA off the top of my head of = a way to take advantage of it - Davey On Nov 30, 2010, at 7:31 PM, 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 > As I replied elsewhere: >=20 > Its not a matter of consistency - Properties, as a cross-language = concept > are not meant to work that way. 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. >=20 > 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. >=20 > __isset is a whole different matter, without it we would have to = assume > that every possible member name in a class either exists or does not > exist. This is because __isset, __get, __set and __unset can handle = ANY > member name. >=20 > Properties are bound to a single member name, therefore, they always > exist, unless you were to physically remove that property from the = class, > which, like methods, that is not possible. >=20 > - Dennis >=20 >=20 > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >=20