Are these if statements always the same in PHP?

Peter

New member
Statement 1:
if(isset($obj)) { }

Statement 2:
if($obj) { }


Are these if statements always the same in PHP? If not, under what situation do they give different results?

Many thanks to you all.
 
In some ways yes, and in some ways no.
If you have the variable $obj set to something, then it will be the same. However, There are things like COOKIES, that are different.
isset($_COOKIE['something']) will see if there is a cookie.
Just plainly using if($_COOKIE['something']) will just try to provide a value OR a boolean value. So when you using cookies, make sure to use the isset. Otherwise, yes, they are identical.
 
Back
Top