際際滷

際際滷Share a Scribd company logo
CLASSES AND OBJECTS
Object Oriented PHP
Class is the combination of variables and functions.
Combined together into one group.
Object is the example of the class who actually uses the class.
Advantage of Using Object Oriented PHP
1. Grouping of code.
2. More Clarity.
3. Classes can be inherited.
4. Automatically initialization of function.
i.e.  Constructor and Destructors
Syntax :-
Class class_name
{
function function_name ( )
{
.
code to be executed..
.
}
}
Class class_name
{
function function_name 1 ( )
{
code to be executed..
}
function function_name 2( )
{
code to be executed..
}
}
Example :-
 class Car
 {
 var $type;
 function __construct($type)
 {
 $this->type = $type;
 }
 function getType()
 {
 return $this->type;
 }
 }
 $myCar = new Car("sports);
 echo "Car type: " . $myCar->getType();
Database Connection Using Class
class test
{
function __construct()
{
$this->c=mysql_connect(HOST,UNAME,PASS)or die("error in connection");
mysql_select_db(DB,$this->c);
}
function login($user,$paas )
{
.......code
}}
$obj= new test;
$obj->insert ( ) ;
Public, Protected, Private
 Public  Access anywhere
 Protected  Access within class and Derived Class
 Private - Access only in class

More Related Content

Classes and objects