anatak Posted June 15, 2007 Share Posted June 15, 2007 hello $error= $db->ErrorMsg(); if(empty($error)){echo 'empty';} works fine if(empty($db->ErrorMsg())){echo 'empty';} does not work. Can someone explain why ? related to empty() I also have this non OOP question if(!isset($var)){echo 'var is not set';} works but if(!empty($var)){echo 'var is not set';} does not work Is there a reason why you can not test for !empty() ?? kind regards anatak thank you Link to comment https://forums.phpfreaks.com/topic/55662-solved-why-does-empty-not-work-on-object/ Share on other sites More sharing options...
emehrkay Posted June 15, 2007 Share Posted June 15, 2007 check the changelog http://us2.php.net/empty your second question says two different things -if it isnt set... -if it is not empty... Link to comment https://forums.phpfreaks.com/topic/55662-solved-why-does-empty-not-work-on-object/#findComment-275108 Share on other sites More sharing options...
per1os Posted June 15, 2007 Share Posted June 15, 2007 On that note, why not create a function in the class that checks the errormsg variable for you something like: <?php if (!$db->errorEmpty()) { } // (note this should be in the class with the right values function errorEmpty() { if (!empty($this->error)) { return true; } return false; } ?> Should work just the same as you intended it, just a little bit less code and less chance for error as you do not have to add !empty() to ever if statement like this it is simply if !$db->errorEmpty() =) Link to comment https://forums.phpfreaks.com/topic/55662-solved-why-does-empty-not-work-on-object/#findComment-275326 Share on other sites More sharing options...
anatak Posted June 17, 2007 Author Share Posted June 17, 2007 sorry for the long wait. About the empty() function. I just wondered why !empty($var) does not work. if(empty($var)){echo $var .'is empty';} //this works if(!empty($var)){echo $var .'is not empty';} //this does not works anyway I can work around it so it is not much of a problem. Thanks for the help with understanding $db->ErrorMsg(); Link to comment https://forums.phpfreaks.com/topic/55662-solved-why-does-empty-not-work-on-object/#findComment-276278 Share on other sites More sharing options...
Jenk Posted June 17, 2007 Share Posted June 17, 2007 You haven't defined $var. Read people's replies carefully, this was answered in the first reply. Link to comment https://forums.phpfreaks.com/topic/55662-solved-why-does-empty-not-work-on-object/#findComment-276344 Share on other sites More sharing options...
anatak Posted December 12, 2007 Author Share Posted December 12, 2007 Jenk, I think that empty($var) checks to see if $var exist (not defined), if $var=null or if $var="" (empty string) if the $var is in any of these conditions the empty() function will return true I was just wondering why !empty() in an if statement did not seem to work. anyway my problem is solved so I will close this topic anatak Link to comment https://forums.phpfreaks.com/topic/55662-solved-why-does-empty-not-work-on-object/#findComment-412385 Share on other sites More sharing options...
Jenk Posted December 12, 2007 Share Posted December 12, 2007 You still didn't read the first reply properly. empty($var) will return true if either $var is undefined, or contains the value of null, 0, "" (empty string) or an empty array. I suggest you read that line very carefully, then read it again carefully, and once more for luck, before replying again. Link to comment https://forums.phpfreaks.com/topic/55662-solved-why-does-empty-not-work-on-object/#findComment-412776 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.