empty($obj->getError())

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

empty($obj->getError())

Post by Ree »

I use $obj->getError() to check if there was an error in performing the last action. It returns the error (string) or an empty string if there was no error. It would be very convenient if I could use

Code: Select all

if (!empty($obj->getError()))
{
  //do error related stuff
}
but I can't since empty() only accepts plain vars. Is there a nice way to replace non-working empty($obj->getError()) with something that could check if $obj->getError() is empty string?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

class foo {
  function err(&$error) {
    $err = 'some error';
    return (bool)$err;
  }
}

$foo = new foo();
if($foo->err($err)) {
  echo $err;
}
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

Post by Ree »

Yes, (bool) is what I need. Thanks, that actually made me check type casting out @ php.net. :)
Post Reply