home

Php Class And Object Tutorial


A class is a blueprint or in other words it's a set of functions (methods) and variables (properties). Classes in PHP make the programming easy. The use of Classes in PHP makes it an Object Oriented Programming Language.

To make a simple class in PHP we need to use a keyword class. In the body of class, we can write it's code. A simple syntax of PHP class is

class className
{

 //code of Class

}

PHP Class Object

As mentioned before a class is just a blueprint or plan, hence it can not work on it's own. To make a class work it must be instatiated, this is done by creating an instance (object) of class. A general syntax of Creating an object of class is

$object_name = new className();

To create an object of class the new construct is used, new will create a new instance of class. Lets have a look at another example of how to create a Class in PHP and then instantiate it by creating an object.

<?php

//class declearation
class vehicle
{

//class code here

}

//class object
$object = new vehicle();

?>


Content on this page requires a newer version of Adobe Flash Player.

Get Adobe Flash player

all rights reseverd by Cramerz.com©. web design london by dotPeak. hosting by HostBay
all contents on cramerz are the property of Cramerz.com