PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Validate » Validate_Finance_CreditCard » Bug #7273

Parameter order for CreditCard::type function signature needx reversing

Details

Submitted2006-03-31 23:21 UTC
Fromandrew_wilkie at yahoo dot com dot au
StatusNo Feedback
PackageValidate_Finance_CreditCard
PHP Version5.1.2
OSMicrosoft Windows XP [Version 5.
Roadmaps(Not assigned)

Comments

[2006-03-31 23:21 UTC] andrew_wilkie at yahoo dot com dot au

Description:
------------
When building the $values and $opts arrays which are passed to Validate::multiple, the values of credit card type and number have to be swapped with each other in order for CreditCard::type to work correctly. This seems to be a bug, but please correct me if I'm missing something.

Test script:
---------------
//===================
// My own code snippet
//===================
// Note 1: $allVals['Credit_card_type'] is MasterCard
// Note 2: $allVals['Credit_card_number']) is my own MC valid number

$values = array(
'Credit_card_type' => $allVals['Credit_card_type'], //This works with CreditCard.php if you swap the param order in the function signature.
//'Credit_card_type' => $allVals['Credit_card_number'], //This works with CreditCard.php package 0.5.2 (alpha)
'Credit_card_number' => $allVals['Credit_card_number']));

$opts = array(
'Credit_card_type' => array('type'=>'Finance_CreditCard_type','creditCard'=>$allVals['Credit_card_number']),//This works with CreditCard.php if you swap the param order in the function signature.
//'Credit_card_type' => array('type'=>'Finance_CreditCard_type','creditCard'=>$allVals['Credit_card_type']),//This works with CreditCard.php package 0.5.2 (alpha)
'Credit_card_number' => array('type' => 'Finance_CreditCard_number'));

$validArray = Validate::multiple($values, $opts);

//===================
// CreditCard.php package 0.5.2 (alpha) code snippet
//===================
//function type($cardType, $creditCard) // my code, i.e. swapped parameters in function definition
function type($creditCard, $cardType) // original code in CreditCard.php package 0.5.2 (alpha)
{
echo "CreditCard::type - creditCard number: " . $creditCard . "<br />"; // my code
echo "CreditCard::type - cardType: " . $cardType . "<br />"; // my code

Expected result:
----------------
CreditCard::type - creditCard number: 5353 1652 7345 5033
CreditCard::type - cardType: MasterCard

Actual result:
--------------
CreditCard::type - creditCard number: MasterCard
CreditCard::type - cardType: 5353 1652 7345 5033