Jump to content

Help with php classes


mpsn

Recommended Posts

Hi, I want to build a simple calculator class and one of the function is to calculate the factorial, but for some reason I cannot get this to work.

 

Here is class:

=========

<?php
class Calculator {

function factorial($n) {
  if($n==1)
return 1;
  else 
return factorial($n-1)*$n;
}	
}//END CLASS Calculator

$calculator=new Calculator();
print $calculator->factorial(3);
?>  

 

But it doesn't work, I know this is simple but I am a little rusty with object oriented programming.

 

I'd appreciated any help!

Link to comment
https://forums.phpfreaks.com/topic/251510-help-with-php-classes/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.