NYCPHP Meetup

NYPHP.org

[nycphp-talk] Difference between isset() and empty() .

David Krings ramons at gmx.net
Fri May 18 10:05:32 EDT 2007


Shadab Wadiwala wrote:
> Hi !!
> 
>         I want to know what's the difference between the functions ----
> isset() and empty()
> 
>         I referred the function reference on php.net, but still couldn't 
> the exact answer to my query.
> 
> 
isset() checks if a key exists in a server array such as $_SESSION or 
$_POST regardless of the value, which can be NULL or an empty string. I 
never used empty(), but just by the name of it that function checks if 
the value of a given variable or array key is considered "nothing" for 
the respective variable type.
I always check if something is set in $_SESSION or $_POST (I rarely use 
get) and then go with that value. In case it is not set I either set a 
known good default value or I set a value that is guaranteed to generate 
an obvious error (means a runtime error, crash, or such).

David



More information about the talk mailing list