Re: Validation functions
| From: | (Alexander Merz) | Date: | Mon, 24 Jun 2002 00:03:23 +0000 |
| Subject: | Re: Validation functions | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-7316@lists.php.net to get a copy of this message | ||
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.