PHP Class Definition

Description

In PHP we use class keyword to define a class.

Syntax

The class definition has the following syntax.


class Car { 
   //properties
   //methods
}   

Example

Here is the PHP code necessary to define a very basic Dog class:


<?PHP/*ww  w.j  a va  2s  .co m*/
class Dog {
   public function bark() {
      print "PHP!";
   }
}
?>

Here the Dog class has just one method, bark().





















Home »
  PHP Tutorial »
    Language Basic »




PHP Introduction
PHP Operators
PHP Statements
Variable
PHP Function Create
Exception
PHP Class Definition