Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:3956 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 39262 invoked from network); 14 Aug 2003 19:37:06 -0000 Received: from unknown (HELO pd4mo1so.prod.shaw.ca) (24.71.223.10) by pb1.pair.com with SMTP; 14 Aug 2003 19:37:06 -0000 Received: from pd3mr1so.prod.shaw.ca (pd3mr1so-ser.prod.shaw.ca [10.0.141.177]) by l-daemon (iPlanet Messaging Server 5.2 HotFix 1.16 (built May 14 2003)) with ESMTP id <0HJM0057QJM9ZS@l-daemon> for internals@lists.php.net; Thu, 14 Aug 2003 13:32:33 -0600 (MDT) Received: from pn2ml1so.prod.shaw.ca (pn2ml1so-qfe0.prod.shaw.ca [10.0.121.145]) by l-daemon (iPlanet Messaging Server 5.2 HotFix 1.16 (built May 14 2003)) with ESMTP id <0HJM00G25JM9RT@l-daemon> for internals@lists.php.net; Thu, 14 Aug 2003 13:32:33 -0600 (MDT) Received: from h24-84-221-8.vc.shawcable.net (h24-84-221-8.vc.shawcable.net [24.84.221.8]) by l-daemon (iPlanet Messaging Server 5.2 HotFix 1.16 (built May 14 2003)) with ESMTP id <0HJM00H28JM8A2@l-daemon> for internals@lists.php.net; Thu, 14 Aug 2003 13:32:33 -0600 (MDT) Date: Thu, 14 Aug 2003 12:32:01 -0700 In-reply-to: <5.1.0.14.2.20030814184144.038a5810@127.0.0.1> To: Andi Gutmans Cc: nicos@php.net, internals@lists.php.net Message-ID: <1060889520.1036.45.camel@ali> Organization: MIME-version: 1.0 X-Mailer: Ximian Evolution 1.2.4 Content-type: text/plain Content-transfer-encoding: 7BIT References: <1060813541.901.336.camel@ali> <5.1.0.14.2.20030814184144.038a5810@127.0.0.1> Subject: Re: [PHP-DEV] Re: variable_exists() patch From: torben@php.net (Lars Torben Wilson) On Thu, 2003-08-14 at 08:42, Andi Gutmans wrote: > I am not really convinced either that variable_exists() is > function_exists() parallel. > Under what circumstances is this needed? > > Andi The followup I sent to Ilia gives examples of how this patch can be used to determine whether, for instance, array keys exist, without having to use the array_key_exists() workaround; also, you can check whether an object has defined an attribute, even if it hasn't yet assigned it a value: bar) ? 'yes' : 'no') . " (should be yes)\n"; echo "variable_exists(\$foo->baz): " . (variable_exists($foo->baz) ? 'yes' : 'no') . " (should be yes)\n"; echo "variable_exists(\$foo->quux): " . (variable_exists($foo->quux) ? 'yes' : 'no') . " (should be yes)\n"; echo "variable_exists(\$foo->quuux): " . (variable_exists($foo->quuux) ? 'yes' : 'no') . " (should be no)\n"; echo "isset(\$foo->bar): " . (isset($foo->bar) ? 'yes' : 'no') . " (should be yes)\n"; echo "isset(\$foo->baz): " . (isset($foo->baz) ? 'yes' : 'no') . " (should be yes)\n"; echo "isset(\$foo->quux): " . (isset($foo->quux) ? 'yes' : 'no') . " (should be yes)\n"; echo "isset(\$foo->quuux): " . (isset($foo->quuux) ? 'yes' : 'no') . " (should be no)\n"; ?> ...the output from the above is: ----------------------------------------------------------------------- variable_exists($foo->bar): yes (should be yes) variable_exists($foo->baz): yes (should be yes) variable_exists($foo->quux): yes (should be yes) variable_exists($foo->quuux): no (should be no) isset($foo->bar): no (should be yes) isset($foo->baz): no (should be yes) isset($foo->quux): yes (should be yes) isset($foo->quuux): no (should be no) ----------------------------------------------------------------------- etc. It's a little annoying at times that that isset() doesn't do what its name suggests it should, which leads people to try to use it for things which is seems that it should be able to do, but can't. When I've tried to explain it, the only answer I can give is "Sorry, that's just the way it is--and no, you can't do that in PHP". It seems basic enough functionality that is almost, but not quite, satisfied by isset(). -- Torben Wilson +1.604.709.0506 http://www.thebuttlesschaps.com http://www.inflatableeye.com http://www.hybrid17.com http://www.themainonmain.com -----==== Boycott Starbucks! http://www.haidabuckscafe.com ====-----