Reputation: 177
I am trying to call a method from a different class in a different file. However, When I run the code i get the following error:
Fatal error: Call to undefined function getFxRate() in fxCalc.php
Here is the code I am trying to build:
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;
}
Any help would be appreciated.
Upvotes: 1
Views: 368
Reputation: 68556
Say if your name of the class infxDataModel.php
is FxModel
Then you need to call your method like
$fxRate = FxModel::getFxRate($inputCurrency, $outputCurrency);
instead of
$fxRate = getFxRate($inputCurrency, $outputCurrency);
That is because your function is declared as static
. The static calls are made by using ::
operator followed by the class name.
Upvotes: 2