Hi!
is_numeric is not good enough in some cases, like when searching for value
in MongoDB where it matches agains typed value.
function age_check(int $age)
{
// do stuff
}
This would require less code, easier to read and will catch wrong type at
runtime easy and throw recoverable fatal error that you can catch.
You can catch and do what? By that time you application has failed with
no chance to recover, since you can't go back to age_check call and say
"oh, sorry, when I said '1' I actually meant integer 1, please accept
it!" The only thing you can do is to output a nice error message, and
since this is nothing the user can correct, since it's not his problem
but a code bug, it'll be something like "something went wrong, oops,
please go to another page of the site and hope it will be programmed
better than this one!". That's pretty much your options when using
strict typed function - unless you either have strict typing throughout
the whole code path(s) that lead to the age_check call or do an explicit
check with explicit failure handling each time you try to call it.
the well designed IDE can also catch error in your code if your parameters
and all returnes are typed, so that will also save you a lot of time.
I start to feel "well designed IDE" is a substitute for a compiler for
some. PHP is not a compiled language, however, at least not yet - and
since it's not, relying on mythical "well designed IDE" to perform the
function that compiler performs in static-typed compiled languages is,
IMHO, misguided.
--
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php