Re: variable_exists() patch
| From: | Lars Torben Wilson | Date: | Thu, 14 Aug 2003 21:05:29 +0000 |
| Subject: | Re: variable_exists() patch | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-3966@lists.php.net to get a copy of this message | ||
On Thu, 2003-08-14 at 14:01, Stefan Walk wrote:
> On Thu, Aug 14, 2003 at 12:00:26PM -0700, walt boring wrote:
> > It can happen quite easily. I always develop with full warnings/errors on.
>
> So do I.
>
> > So if for example a var isn't set for whatever reason, then trying to
> > access the
> > variable will throw a php Notice. variable_exists() would prevent that,
> > as does isset().
>
> Correct, isset works.
>
> > isset() would work for my example below, but it still is a 'broken'
> > function in my opinion.
> >
> > if ($var) { // <-- you'll get a php notice on this line
> > switch ($var) {
> > ...
> > }
> >
> > }
> >
> > versus doing
> >
> > if (variable_exists($var)) { //no php notices here
> > switch($var) {
> > ...
> > }
> > }
>
> As you already stated, isset works also. I asked for an occasion where
> your variable_exists would be useful because isset does not work.
>
> DB arguments don't count, if a value is null in a database it is
> considered - you guessed it - not set.
>
> I simply don't see a need for this.
I have posted several examples, complete with code and output.
--
Torben Wilson <torben@php.net> +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 ====-----