Posted by Umberto Salsi on 10/03/74 11:32
"Thomas Mlynarczyk" <blue_elephant55@hotmail.com> wrote:
> What I'm looking for is the best suited general return value for cases where
> an operation could not be successfully completed as expected and the
> function is not able to fix the error by itself and the error is of a nature
> where "drastic measures" like throwing an error or an exception would be
> inappropriate.
You might return the handle to an object created specifically to indicate
the error condition:
class Err
{
static $raised = NULL;
function __construct()
{
self::$raised = $this;
}
}
new Err();
function myfunc($n)
{
if( invalid $n )
return Err::$raised;
else
return something;
}
$res = myfunc(123);
if( $res === Err::$raised )
echo "Error!";
The value Err::$raised cannot be confused with any other value a function
may return.
Regards,
___
/_|_\ Umberto Salsi
\/_\/ www.icosaedro.it
Navigation:
[Reply to this message]
|