I am trying to call a function from outside a class and having problems:
class Factorial{
public function factorial($number) {
if ($number < 2) {
return 1;
} else {
return ($number * factorial($number-1));
}
}
}
$f = new Factorial();
echo $f->factorial(5);
Can someone please point me in the right direction?
Thank you so much
Your problem is not outside, but inside:
If you want to refer to another method you have to use
$this->methodnamewhere$thisrefers the instance:I suggest to read PHP – OOP – The Basics.