Re: Validation functions
| From: | Alan Knowles | Date: | Mon, 24 Jun 2002 02:58:03 +0000 |
| Subject: | Re: Validation functions | ||
| References: | 1 2 3 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-7318@lists.php.net to get a copy of this message | ||
this is a bit like saying is gpc_magic_quotes turned on? -
if it is the $_POST['x'] = "\'somedata";
otherwise it is
$_POST['x'] = "'somedata";
the problem is that it is configurable and it changes the way the application works - this tends to lead to installations, and code that breaks as soon as you move it around.
The principle that a function has a fixed set (and minimal) possiblities of returning something - easy to explain what it does, easy to use and easy to document.. - something php mostly acheives :)
perhaps what is needed here is:
Validate core: - which returns TRUE/FALSE, and logs errors (and is really as set of static methods) - or what ever it does at present?
Validate pear: - which returns PEAR_ERROR - which can can be a more 'pear_error' orientated view of validate - and just relays stuff to validate core..
I dont think trying to mix the two is going to help anybody....
I can see the code below being valid, but 'personally' <- note maybe only me and maybe this month only :) - would just use the easy direct stuff today (as it's an easy introduction.. - if I want to make the code better, more standard - move to the pear version.... - typical php situation, do it the easy way first, do it the proper way later....
regards
alan
Alexander Merz wrote:
Alan Knowles wrote:Imagine doing database code after setting the error handling to numerical.. - it's going to break all your error testing for the database code if you forget to turn error back to object based..Depends on your implemention :-) Just try this code <?php include "PEAR.php"; class MyValidation extends PEAR {function validateMe( $test) { if($test) { return true; } else { if($this) { $this->raiseError("not true", -1); } else { PEAR::raiseError("not true", -1, PEAR_ERROR_TRIGGER, E_USER_WARNING) ; } } }} PEAR::SetErrorHandling(PEAR_ERROR_DIE, "i'm dead"); echo "first call:\n"; MyValidation::validateMe(false); // creates a warning, does not die! $val = new MyValidation ; $val->SetErrorHandling(PEAR_ERROR_PRINT, "I'm printed\n"); echo "second call:\n"; $val->validateMe(false); // prints the message $val2 = new MyValidation ; echo "thirth call:\n"; $val2->validateMe(false); // dies! So if you use the implementation above you can let the user decide about how to handle an error. He can set the handling local or global.