Re: Validation functions

From: Date: Mon, 24 Jun 2002 12:21:01 +0000
Subject: Re: Validation functions
References: 1 2 3 4  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-7323@lists.php.net to get a copy of this message
Pierre-Alain Joye wrote:
Do you want Validate return/raise a pear error on a non valid data ? => (1)
$val = new MyValidation ; $val->validateMe(false); // prints the message Have I understood what you said ? (2)
Usage has been thinked like : if (Validate::validateMe(false)){...
Both versions are correct, the difference between this two types is the way of handling in case of non-valid data. If called staticly (2) only true or false would be returned, if you call through an instance (1) raiseError is used. Another point you should not forget are complex valdations functions. Ie. i've wrote a validation function for checking german bank account numbers (but never finished). This functions requires two parameters: The bank code number and the account number. In germany there exists at the moment 100 different checksum routines. So the function first looks up in a database which routine to use. Then the function calls the routine and checks the number. In this situation you have three states: - the account number is correct - the account number is not correct - the account number can not be checked, because db look up fails or the account number needs to be checked by a new checksum routine, which isn't implemented yet (really possible) What to do now? Returning 'false' in the last case is'nt really usable, because the number may be correct. And at the end, don't forget usability. As a user of your application, i would intrested in what is wrong, not only that something is wrong. A validation method which only returns true/false doesn't give the required information

« previous php.pear.dev (#7323) next »