Re: Validation functions

From: Date: Sun, 23 Jun 2002 01:35:01 +0000
Subject: Re: Validation functions
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-7300@lists.php.net to get a copy of this message
So the problem is just, that a user maybe wants to recieve a constant instead of a PEAR_Error object. So what is the problem? What about this: ------------- // set errorhandling to return the errorcode instead of a PEAR_Error PEAR::setErrorHandling( PEAR_ERROR_CONSTANT); if (($res = Validate::number(100, null, null, 1, 10)) < 0) {
         if ($res == VAL_E_OUTOFRANGE)
                 die("Only values between 1 and 10 are allowed");
         else
                 die("You have to submit a number here");
} // now switch to 'normal' handling PEAR::setErrorHandling(); if (PEAR::isError($error = Validate::number(...)) { die("Validation failed"); } // or the same like above... PEAR::setErrorHandling(PEAR_ERROR_DIE, "Validation failed"); $error = Validate::number(...) ------------- add to PEAR.php function raiseError(...) { .. case PEAR_ERROR_CONSTANT : ... return $error_code ; ... } --------------- So the user gets the full power about error handling.

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