Calling a function within a class

Posted by JM4 on Stack Overflow See other posts from Stack Overflow or by JM4
Published on 2010-05-13T03:28:09Z Indexed on 2010/05/13 3:34 UTC
Read the original article Hit count: 279

Filed under:
|
|
|

I am having trouble calling a specific function within a class. The call is made:

   case "Mod10":        
        if (!validateCreditCard($fields[$field_name]))
      $errors[] = $error_message;
    break;

and the class code is:

class CreditCardValidationSolution {

    var $CCVSNumber = '';
    var $CCVSNumberLeft = '';
    var $CCVSNumberRight = '';
    var $CCVSType = '';
    var $CCVSError = '';

function validateCreditCard($Number) {

        $this->CCVSNumber      = '';
        $this->CCVSNumberLeft  = '';
        $this->CCVSNumberRight = '';
        $this->CCVSType        = '';
        $this->CCVSError       = '';

        // Catch malformed input.

        if (empty($Number) || !is_string($Number)) {
            $this->CCVSError = $CCVSErrNumberString;
            return FALSE;
        }

        // Ensure number doesn't overrun.
        $Number = substr($Number, 0, 20);

        // Remove non-numeric characters.
        $this->CCVSNumber = preg_replace('/[^0-9]/', '', $Number);

        // Set up variables.
        $this->CCVSNumberLeft  = substr($this->CCVSNumber, 0, 4);
        $this->CCVSNumberRight = substr($this->CCVSNumber, -4);
        $NumberLength          = strlen($this->CCVSNumber);
        $DoChecksum            = 'Y';

        // Mod10 checksum process...
        if ($DoChecksum == 'Y') {

            $Checksum = 0;

            // Add even digits in even length strings or odd digits in odd length strings.
            for ($Location = 1 - ($NumberLength % 2); $Location < $NumberLength; $Location += 2) {
                $Checksum += substr($this->CCVSNumber, $Location, 1);
            }

            // Analyze odd digits in even length strings or even digits in odd length strings.
            for ($Location = ($NumberLength % 2); $Location < $NumberLength; $Location += 2) {
                $Digit = substr($this->CCVSNumber, $Location, 1) * 2;
                if ($Digit < 10) {
                    $Checksum += $Digit;
                } else {
                    $Checksum += $Digit - 9;
                }
            }

            // Checksums not divisible by 10 are bad.
            if ($Checksum % 10 != 0) {
                $this->CCVSError = $CCVSErrChecksum;
                return FALSE;
            }
        }

        return TRUE;
}
}

When I run the application - I get the following message:

Fatal error: Call to undefined function validateCreditCard() in C:\xampp\htdocs\validation.php on line 339

any ideas?

© Stack Overflow or respective owner

Related posts about class

Related posts about php