Difference between revisions of "PHP:Define a Class"

From Progzoo
Jump to: navigation, search
Line 1: Line 1:
 +
 
class Person {
 
class Person {
 
   public $name;
 
   public $name;

Revision as of 15:02, 12 February 2009

class Person {

 public $name;
 private $weight, $height;
 public function __construct($name, $weight, $height)
 {
   this->name = $name;
   this->weight = $weight;
   this->height = $height;
 }
 public function bmi()
 {
   $bmi = $this->weight / $this->height / $this->height;
   return $bmi;
 }

}

$p = new Person("andrew",99,1.8); Echo ($p->bmi()); Echo ($p->n);