Page 1 of 1

empty($obj->getError())

Posted: Fri Oct 07, 2005 2:16 pm
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?

Posted: Fri Oct 07, 2005 2:24 pm
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;
}

Posted: Fri Oct 07, 2005 2:40 pm
by Ree
Yes, (bool) is what I need. Thanks, that actually made me check type casting out @ php.net. :)