PHP:Define a Class

From Progzoo
Revision as of 15:02, 12 February 2009 by 08011145 (talk | contribs)
Jump to: navigation, search

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);