RE: isset

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> how I understand:
> clause one: isset($_GET['var'])
> clause two: ($_GET['var'] == 'foo')
> if clause two is true, clause one MUST be true.
> if clause one is true, clause two could be true or false.
>
> means, if I look for solutions where ($_GET['var'] == 'foo') they wil
> lautomaticaly cover isset($_GET['var']) part.
> if ($_GET['var'] != 'foo') I erally do not care isset($_GET['var']) or
> !isset($_GET['var']).

If you are looking for 

isset($_GET['var'])

to return true if the value exists, but may be null, you can always use 

if (isset($_GET['var']) || is_null($_GET['var]))

Albeit, I'm unsure if this will generate a warning if $_GET['var']
doesn't exist for the is_null() call.  And in this case, I believe it
would be appropriate to ignore that one warning.

-Logan

-----Original Message-----
From: Larry Garfield [mailto:larry@xxxxxxxxxxxxxxxx] 
Sent: Sunday, April 15, 2007 1:17 PM
To: php-general@xxxxxxxxxxxxx
Subject: Re:  isset

On Sunday 15 April 2007 12:07 pm, afan@xxxxxxxx wrote:

> > of course it's your call whether you write/run code that spits out
> > E_NOTICEs all over the place due to usage of uninitialized vars.
>
> not quite sure. if $_GET['var'] doesn't exists it's DEFINITLY not
equal to
> 'foo', right?
>
>
> or I'm missing something here?
>
> I have E_NOTICE turned off. :)

And right there is your first mistake.  The only time to not have
E_NOTICE on 
is when you're using legacy code that isn't E_NOTICE compliant and you
don't 
have the time to upgrade it to be compliant.  Developing without
E_NOTICE 
means you're telling the computer "it's OK, let me just randomly guess
where 
this bug or security hole or random typo is".  *Bad* idea.  

*Always* develop in the tightest, most restricted, most nit-picky
setting you 
can get, regardless of the language.  

If you want your syntax to be a bit simpler, I frequently use helper
functions 
along these lines:

function http_get_int($var, $default=0) {
  return isset($_GET[$var]) ? (int) $_GET[$var] : $default;
}

if (http_get_int('var') ==5) {
  // Do stuff
}

Clean to read, easy defaults, (reasonably) type-safe, and E_NOTICE
friendly.

-- 
Larry Garfield			AIM: LOLG42
larry@xxxxxxxxxxxxxxxx		ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an
idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the
possession 
of every one, and the receiver cannot dispossess himself of it."  --
Thomas 
Jefferson

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux