Difference between revisions of "PHP:Define a Class"

From Progzoo
Jump to: navigation, search
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
{{topTenTips}}
 
{{topTenTips}}
 
<question className='Hello' lang='php'>
 
<question className='Hello' lang='php'>
The class Person has  
+
The class Person has:
 
*a constructor: <code>__construct</code>
 
*a constructor: <code>__construct</code>
 
*attributes <code>name, weight</code> and <code>height</code>  
 
*attributes <code>name, weight</code> and <code>height</code>  
Line 23: Line 23:
 
}
 
}
  
$p = new Person("andrew",99,1.8);
+
  $p = new Person("andrew",99,1.8);
echo ($p->bmi()."\n");
+
  print ($p->bmi()."\n");
echo ($p->name);
+
  print ($p->name);
 
?>
 
?>
 
]]></prog>
 
]]></prog>
 
</question>
 
</question>

Latest revision as of 14:16, 19 February 2009

The class Person has:

  • a constructor: __construct
  • attributes name, weight and height
  • a method: bmi


[Font] [Default] [Show] [Resize] [History] [Profile]