Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:3970 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 47636 invoked by uid 1007); 15 Aug 2003 04:47:42 -0000 Message-ID: <20030815044742.47635.qmail@pb1.pair.com> To: internals@lists.php.net References: <1060813541.901.336.camel@ali> <5.1.0.14.2.20030814184144.038a5810@127.0.0.1> <1060889520.1036.45.camel@ali> Date: Fri, 15 Aug 2003 01:47:44 -0300 Lines: 79 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 X-Posted-By: 200.196.104.198 Subject: Re: [PHP-DEV] Re: variable_exists() patch From: cunha17@uol.com.br ("Cristiano Duarte") +1 for variable_exists Cristiano Duarte "Lars Torben Wilson" escreveu na mensagem news:1060889520.1036.45.camel@ali... > 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: > > class foo { > var $bar; > var $baz = null; > var $quux = 'quux'; > } > $foo = new foo; > > echo "variable_exists(\$foo->bar): " . (variable_exists($foo->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 ====----- > > >