Re: Strong typing?

From: Date: Fri, 13 Jul 2001 00:27:28 +0000
Subject: Re: Strong typing?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-57659@lists.php.net to get a copy of this message
> Ummmm... you could write a fuction like > > function CheckInputAgainstRE( $val, $re ) > { > if ( ! ereg( $re, $val ) ) > { > ( ... some kind of code that writes out an error message and dies > ... ) > } > return $val; > } That's what I've done. I have a huge file full of all kinds of data checking functions. However, what if I forget to call one of them, or one doesn't work the way I expect it to? Strong typing means that the script will just die, instead of possibly passing the wrong values into the SQL query. This is exactly the same reason why perl has a strict mode. Sure you could write a lot of input checking functions (which you will have to do no matter what) but you should have constraints built into your data structures. It's just like with SQL: if you know that a certain value in a table has a certain constraint ("a withdrawal must always be greater than zero") then you should put that constraint into your table definition, so that an error somewhere else will be limited in its effects. If you're doing financial stuff, or anything else that requires bullet-proof security and reliability, strong typing is essential, in addition to checking all the user input.

« previous php.general (#57659) next »