Re: Should return "TRUE or PEAR_Error" ???

From: Date: Mon, 20 Jul 2009 22:43:48 +0000
Subject: Re: Should return "TRUE or PEAR_Error" ???
References: 1 2  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-52430@lists.php.net to get a copy of this message
> It would make more sense to keep a TRUE / FALSE return value and throw a >  PEAR_Exception($error) when your code gets a PEAR_Error internally. > > This means TRUE and FALSE are expected values when calling the method. > If a problem occurred and a TRUE or FALSE cannot be safely determined, > then it's an exceptional situation. > I would second Philippe's idea about throwing an exception but I woudl push it even further by saying that you should have your own exception class and you throw that one. The definition of the custom exception class is as simple as this: class Mail_CheckUser_Exception extends PEAR_Exception (Or Exception) {} This way then in your methods you'll simply do: /** * Short desc * * Longer desc * * @throws Mail_CheckUser_Exception * @param type name desc * @return boolean true or false depending on the result */ access function name(name) { throw new Mail_CheckUser_Exception('Something to tell your users..'); return false; } >> Thanks >> Sorry, if I mistake English. Your english is fine really :) Don't worry about that -- Slan, David

« previous php.pear.dev (#52430) next »