Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:50774 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 72880 invoked from network); 1 Dec 2010 12:56:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Dec 2010 12:56:42 -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.83 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.83 caiajhbdcaid.dreamhost.com Linux 2.6 Received: from [208.97.132.83] ([208.97.132.83:47363] helo=homiemail-a22.g.dreamhost.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id EA/E1-62427-90646FC4 for ; Wed, 01 Dec 2010 07:56:42 -0500 Received: from homiemail-a22.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a22.g.dreamhost.com (Postfix) with ESMTP id BCFB51A8076; Wed, 1 Dec 2010 04:56:38 -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=wxepVfQWydDv4BtRf680Ii1gS0n0IKt+giGHAy74TFR/v oeC+01oN+LedN+Ps+Wu+3U/Nq8A1dCYUtK/gtrrbpPFsnqvxsTT969RH+hxI4eUd FZSrCAI+5LBviuk3Xk0olFhgx9hUzIeMyQg2KhioYN5teWDfD28hi8o0bXjS8w= 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=zqg8gAIWVme024NqJLMKnk4QjaU=; b=ScTVPRMIdbyG 8QlWMNkReDAXuUpTTztslQcwFZQnWuzBnc31nAdzfGAqX+GqiB/VTH4UZMbkEnwG 1A0vOwEWciWyLEkBXBVjpBh6XMQtbHa9zoiO0LLoyYXvmIQdOpRI6rSeuBBljdtA CLzcxkJaW8CmkTFfSTVDrZiBWfsH7Lg= Received: from webmail.basnetworks.net (caiajhbdcaib.dreamhost.com [208.97.132.81]) (Authenticated sender: president@basnetworks.net) by homiemail-a22.g.dreamhost.com (Postfix) with ESMTPA id 7F06C1A8063; Wed, 1 Dec 2010 04:56:38 -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; Wed, 1 Dec 2010 07:56:42 -0500 Message-ID: <259248af48309dce44dc82e3d7371547.squirrel@webmail.basnetworks.net> In-Reply-To: <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> <4CA4675C-62DB-4808-ACB0-0F91391A81CA@php.net> Date: Wed, 1 Dec 2010 07:56:42 -0500 To: "Davey Shafik" Cc: president@basnetworks.net, "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 Hi Davey, > 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? I did not know of property_exists(), very interesting! > In this case, both isset() and unset() work with the property get/set y= ou > are proposing. Imagine: > > $results =3D $db->query('SELECT SQL_CALC_FOUND_ROWS * FROM some_table W= HERE > 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 o= f a > way to take advantage of it Well, I understand the concept and how it would work, but I just don't think its logical. In my mind, being able to make a property appear to disappear makes as much sense as making a class method appear to disappear. This is absolutely no good for inheritance for one thing. The __isset method makes perfect sense, because all variables handled wit= h __get and __set don't truly exist. They are not actually defined in the class, they are just "fake" class members, whose data comes from somewher= e else - maybe an array. So __isset is there to say which "fake" member names do and don't exist. But when defined, a property, like a method, shouldn't be able to just "disappear". It is a specific definition and should never appear to be missing. If you need a class member that can be unset, you should be using __isset __get and __set, because that is exactly what those are meant for. My feelings are that a property "foo" should behave exactly like a getFoo() and setFoo($value) pair of methods. You can always call these methods, and never worry that you will get a "method not set" error. Whe= n you call getFoo() you are always guaranteed to get something, even if it is simply NULL. Maybe I am missing your point? But it does not make logical sense to me, the way you suggest. Also, would adding isset not make properties much slower? Calling $object->foo would first have to call and process the "isset" method to determine if it is set, then after getting "true" from isset, it would be able to call "get". And what happens if there is no "isset"? Is it just always guaranteed to be set then? - Dennis