Page 1 of 1
isset and != ''
Posted: Sun Feb 20, 2005 3:29 pm
by jonemo
is there any difference between the following two code snippets?
i.e. can it happen that the two conditions have different results with the same $t?
Posted: Sun Feb 20, 2005 3:33 pm
by feyd
the second can, and will produce an "undefined variable: t" error/warning/notice. The first will not.
Posted: Sun Feb 20, 2005 3:42 pm
by John Cartwright
you're better off using
empty() and isset()
feyd | 
Posted: Sun Feb 20, 2005 4:02 pm
by timvw
with array keys there are some differences between != '', isset, array_key_existst and empty.
Posted: Sun Feb 20, 2005 4:06 pm
by jonemo
so what is the difference between between empty() and isset() then? and is it only for arrays or is a variable that gets the value NULL still set? as the main use for stuff like that is to check $_REQUEST[] stuff, it deals with arrays...
Posted: Sun Feb 20, 2005 4:13 pm
by timvw
how about reading the manual and experimenting yourself?
Code: Select all
<?php
echo "<br>nothing set<br>";
if (isset($val))
{
echo "isset";
}
else
{
echo "not isset";
}
echo "<br>";
if (empty($val))
{
echo "empty";
}
else
{
echo "not empty";
}
echo "<br> assign test<br>";
$val = "test";
if (isset($val))
{
echo "isset";
}
else
{
echo "not isset";
}
echo "<br>";
if (empty($val))
{
echo "empty";
}
else
{
echo "not empty";
}
echo "<br>assign null<br>";
$val = null;
if (isset($val))
{
echo "isset";
}
else
{
echo "not isset";
}
echo "<br>";
if (empty($val))
{
echo "empty";
}
else
{
echo "not empty";
}
echo "<br>";
?>
feyd | naughty timvw! 
Posted: Sun Feb 20, 2005 5:31 pm
by jonemo
why not ask the clever people in the forum before writing test scripts?
thanks for the code, but i actually just coded the same (before i saw your answer)
