PHP Class Definition

In this chapter you will learn:

  1. How to define a class
  2. Syntax to define a class
  3. Example - Define a class

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/*from java 2  s .  com*/
class Dog {
   public function bark() {
      print "PHP!";
   }
}
?>

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

Next chapter...

What you will learn in the next chapter:

  1. How to create object
  2. Syntax to create object
  3. Objects Within Objects
Home » PHP Tutorial » PHP Class Definition
Concept for Object Oriented Design
PHP Class Definition
PHP Create Object from Class
PHP Class Properties
PHP Iterating Object Properties
PHP Class Inheritance
PHP Overriding Methods
PHP final Classes and Methods
PHP Abstract Class
PHP Class Access Control Modifiers
PHP Class Constructor
PHP Class Destructors
PHP Class Magic Methods