我正在尝试从不同文件中的不同类调用方法。但是,当我运行代码时,我收到以下错误:
致命错误:在fxCalc.php中调用未定义的函数getFxRate()
以下是我要构建的代码:
fxCalc.php
//call fxDataModel class
require_once('fxDataModel.php');
$fxRate = getFxRate($inputCurrency, $outputCurrency);
$txtOutput = $txtInput * $fxRate;
fxDataModel.php
public static function getFxRate($inputCurrency, $outputCurrency)
{
$fxRate = $currencies[$inputCurrency][$outputCurrency];
return $fxRate;
}
任何帮助都将不胜感激。
答案 0 :(得分:2)
说明fxDataModel.php
中您的班级名称是FxModel
然后你需要像
那样调用你的方法 $fxRate = FxModel::getFxRate($inputCurrency, $outputCurrency);
而不是
$fxRate = getFxRate($inputCurrency, $outputCurrency);
这是因为你的函数被声明为static
。静态调用是使用::
运算符后跟类名。