我在調用類中的特定函數時遇到問題。電話可以撥出:調用類中的函數
case "Mod10":
if (!validateCreditCard($fields[$field_name]))
$errors[] = $error_message;
break;
和類代碼:
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;
}
}
當我運行應用程序 - 我得到以下信息:
Fatal error: Call to undefined function validateCreditCard() in C:\xampp\htdocs\validation.php on line 339
什麼想法?
我沒有在課堂上使用開關盒。我在以下內容: Function1()試圖調用Function2()和Function2()生活在ClassA,但功能1不 我還沒有繼承它 - 我對此非常新,老實說,我不甚至知道這意味着什麼,但我認爲你是對的。我試圖從外部調用一個駐留在類內部的函數 – JM4 2010-05-13 04:11:06