Difference between revisions of "PHP:Define a Class"

From Progzoo
Jump to: navigation, search
Line 2: Line 2:
 
<question className='Hello' lang='php'>
 
<question className='Hello' lang='php'>
 
The class Person has  
 
The class Person has  
*a constructor: <code>Person</code>
+
*a constructor: <code>__construct</code>
*attributes <code>n, w</code> and <code>h</code>  
+
*attributes <code>name, weight</code> and <code>height</code>  
 
*a method: <code>bmi</code>
 
*a method: <code>bmi</code>
 
<prog><![CDATA[
 
<prog><![CDATA[
Line 24: Line 24:
  
 
  $p = new Person("andrew",99,1.8);
 
  $p = new Person("andrew",99,1.8);
  echo ($p->bmi());
+
  echo ($p->bmi()."\n");
 
  echo ($p->name);
 
  echo ($p->name);
 
?>
 
?>
 
]]></prog>
 
]]></prog>
 
</question>
 
</question>

Revision as of 16:42, 13 February 2009

The class Person has

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


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