SchweppesAle Posted October 26, 2009 Share Posted October 26, 2009 was hoping someone could explain the difference. Does isset just require fewer operations? edit: also, I just found this empty() function. empty — Tests whether a variable is defined and contains a non-empty and nonzero value. Again, what's the difference Quote Link to comment https://forums.phpfreaks.com/topic/179100-solved-difference-between-isset-and-null/ Share on other sites More sharing options...
Daniel0 Posted October 26, 2009 Share Posted October 26, 2009 The language construct isset() checks if a variable is set while a null comparison checks if some sort of value equals the special value "null". empty() checks if the value of something can be considered empty (the manual tells what values those would be). Quote Link to comment https://forums.phpfreaks.com/topic/179100-solved-difference-between-isset-and-null/#findComment-944943 Share on other sites More sharing options...
SchweppesAle Posted October 26, 2009 Author Share Posted October 26, 2009 The language construct isset() checks if a variable is set while a null comparison checks if some sort of value equals the special value "null". right, but what exactly does "set" mean. I understand NULL Quote Link to comment https://forums.phpfreaks.com/topic/179100-solved-difference-between-isset-and-null/#findComment-944945 Share on other sites More sharing options...
Daniel0 Posted October 26, 2009 Share Posted October 26, 2009 It means that it has been defined somewhere. For instance, if the following is a complete script, the variable $foo is not set, but the variable $var is: <?php $bar = 'foo'; var_dump(isset($foo), isset($bar)); Quote Link to comment https://forums.phpfreaks.com/topic/179100-solved-difference-between-isset-and-null/#findComment-944946 Share on other sites More sharing options...
Alex Posted October 26, 2009 Share Posted October 26, 2009 The language construct isset() checks if a variable is set while a null comparison checks if some sort of value equals the special value "null". right, but what exactly does "set" mean. I understand NULL Has a value other than NULL. Ex: $var = null; // is NOT set while.. $var = ''; // is set Quote Link to comment https://forums.phpfreaks.com/topic/179100-solved-difference-between-isset-and-null/#findComment-944948 Share on other sites More sharing options...
Daniel0 Posted October 26, 2009 Share Posted October 26, 2009 Right, but there is the important distinction that isset() works on undefined variables. Quote Link to comment https://forums.phpfreaks.com/topic/179100-solved-difference-between-isset-and-null/#findComment-944954 Share on other sites More sharing options...
SchweppesAle Posted October 26, 2009 Author Share Posted October 26, 2009 It means that it has been defined somewhere. For instance, if the following is a complete script, the variable $foo is not set, but the variable $var is: <?php $bar = 'foo'; var_dump(isset($foo), isset($bar)); right, so I'm assuming isset($foo) will return false and isset($bar) will return true. in a conditional statement I would say if(isset($bar)) { echo var_dump($bar); } how is that any different from the following though? if($bar != NULL) { echo var_dump($bar); } Quote Link to comment https://forums.phpfreaks.com/topic/179100-solved-difference-between-isset-and-null/#findComment-944973 Share on other sites More sharing options...
Mchl Posted October 26, 2009 Share Posted October 26, 2009 In toher words checking if $var != null will throw E_NOTICE error while isset($var) will not (when $var is not set) Quote Link to comment https://forums.phpfreaks.com/topic/179100-solved-difference-between-isset-and-null/#findComment-944974 Share on other sites More sharing options...
SchweppesAle Posted October 26, 2009 Author Share Posted October 26, 2009 Right, but there is the important distinction that isset() works on undefined variables. I guess that's true if I hadn't declared $bar at all. Still, I guess it comes down to performance if that's the case. Should I avoid "!= NULL" condition statements and stick with isset() for now on? Quote Link to comment https://forums.phpfreaks.com/topic/179100-solved-difference-between-isset-and-null/#findComment-944975 Share on other sites More sharing options...
SchweppesAle Posted October 26, 2009 Author Share Posted October 26, 2009 Man i love google. Thanks again, I think I understand now. http://www.danielnorton.com/nerd/code/php/isdef I was assuming that undefined == NULL. Quote Link to comment https://forums.phpfreaks.com/topic/179100-solved-difference-between-isset-and-null/#findComment-944979 Share on other sites More sharing options...
gizmola Posted October 26, 2009 Share Posted October 26, 2009 Right, but there is the important distinction that isset() works on undefined variables. I guess that's true if I hadn't declared $bar at all. Still, I guess it comes down to performance if that's the case. Should I avoid "!= NULL" condition statements and stick with isset() for now on? Again, there are 2 different concepts: "isset" -> does this symbol exist in the PHP symbol table. "NULL" -> does a matching symbol exist, however there is no associated value. Quote Link to comment https://forums.phpfreaks.com/topic/179100-solved-difference-between-isset-and-null/#findComment-944980 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.