[UPHPU] Coding Correctness

Ash ashovi at qwest.net
Thu Oct 9 12:23:47 MDT 2008


Kirk Cerny wrote:
> What about error handling the case where a sting is passed to the function?
> This function handles the '3', and the 'your name'
> 
> function evenOrOdd ($number) {
>     if (is_numeric($number)) {
>         $evenOrOdd = 'odd';
>         if (($number % 2) == 0)
>         {
>           $evenOrOdd = 'even';
>         }
>         print $evenOrOdd."\n";
>     }
>     else {
>         throw new Exception('Argument is invalid, it must be a number');
>     }
> }
> 
> 
> - Kirk
> 
> 

That error message is kinda wtf'y. "Argument is invalid, it must be a
number" could mean, "you put in a number, and that's invalid" (it must
have been a number) or it could mean "your input should be in the form
of a number, whatever you input is invalid." Which is it?

This is kind of turning into that WTF article, isn't it. :)

Ash



More information about the UPHPU mailing list