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


_______________________________________________

UPHPU mailing list
[email protected]
http://uphpu.org/mailman/listinfo/uphpu
IRC: #uphpu on irc.freenode.net

Reply via email to