php_guest Posted February 2, 2011 Share Posted February 2, 2011 Is if($variable) the same as if(!empty($variable)), just different syntax? Link to comment https://forums.phpfreaks.com/topic/226498-ifemptyvariable-and-ifvariable-the-same/ Share on other sites More sharing options...
BlueSkyIS Posted February 2, 2011 Share Posted February 2, 2011 no, they are not the same. http://php.net/manual/en/function.empty.php Link to comment https://forums.phpfreaks.com/topic/226498-ifemptyvariable-and-ifvariable-the-same/#findComment-1169058 Share on other sites More sharing options...
coupe-r Posted February 2, 2011 Share Posted February 2, 2011 I believe it means if the var ISSET(), but not possitive. Link to comment https://forums.phpfreaks.com/topic/226498-ifemptyvariable-and-ifvariable-the-same/#findComment-1169059 Share on other sites More sharing options...
BlueSkyIS Posted February 2, 2011 Share Posted February 2, 2011 isset is also not the same as empty http://php.net/manual/en/function.isset.php Link to comment https://forums.phpfreaks.com/topic/226498-ifemptyvariable-and-ifvariable-the-same/#findComment-1169060 Share on other sites More sharing options...
coupe-r Posted February 2, 2011 Share Posted February 2, 2011 Right, I was referring to if($var) == ISSET($vav), No? Link to comment https://forums.phpfreaks.com/topic/226498-ifemptyvariable-and-ifvariable-the-same/#findComment-1169063 Share on other sites More sharing options...
BlueSkyIS Posted February 2, 2011 Share Posted February 2, 2011 no i don't think so, at least not if $var is not defined. in which case if ($var) { // will throw an undefined variable notice, and will return NULL if (isset($var)) { // will not throw a notice, and will return a boolean false Link to comment https://forums.phpfreaks.com/topic/226498-ifemptyvariable-and-ifvariable-the-same/#findComment-1169069 Share on other sites More sharing options...
coupe-r Posted February 2, 2011 Share Posted February 2, 2011 10-4 thanks Link to comment https://forums.phpfreaks.com/topic/226498-ifemptyvariable-and-ifvariable-the-same/#findComment-1169071 Share on other sites More sharing options...
php_guest Posted February 2, 2011 Author Share Posted February 2, 2011 But in which way are not the same? With values beeing $var=""; $var=0; $var=false; $var="0"; $var=1; $var="string" the following statements output the same if($var)... if(!empty($var))... So in which example would they output different? Link to comment https://forums.phpfreaks.com/topic/226498-ifemptyvariable-and-ifvariable-the-same/#findComment-1169088 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.