Re: RFC: Credit card processing
| From: | Bertrand Mansion | Date: | Sat, 13 Dec 2003 11:03:01 +0000 |
| Subject: | Re: RFC: Credit card processing | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-24385@lists.php.net to get a copy of this message | ||
<lists@blueroot.net> wrote :
>> Well, best until we can overload '=='. But not too much more code is required
>> to check a class of a return.
>>
>
> it may not be much extra, but it isnt 'nice'
>
> if (Validate::creditCard($ccno)){
> echo "valid";
> }
> else {
> echo "Invalid";
> }
>
> compared to
>
> $ret = Validate::creditCard($ccno)
> if (get_class($ret)=="PEAR_Result"){
> echo "Valid";
> }
> if (get_class($ret)=="PEAR_Error"){
> echo "Invalid"
> }
$ret = CreditCard::validate($ccno);
if (CreditCard::isError($ret)) {
die ($ret->getMessage());
}
Please have a look at PEAR_Error, IMO that's the way to go for your class.
Besides, I don't think it should be integrated into the Validate package
directly. It should live on its own, in whatever category you want.
Then Validate can integrate a function to make a request to your package and
return true/false. If you use PEAR::raiseError, then the error can probably
be caught by some other script somewhere else during the validation process
in order to get the corresponding error message.
Or have a singleton with a static property that stores the last error
message so that other classes like QuickForm can use it later on.
$ret = Validate::creditCard($ccno);
if ($ret === false) {
$ccObj =& CreditCard::singleton();
die($ccObj->getLastErrorCode());
}
Bertrand Mansion
Mamasam