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 Quote Link to comment 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... Quote Link to comment 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() =) Quote Link to comment 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(); Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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.