SlideShare a Scribd company logo
OOPSOOPS
-Concepts in-Concepts in
PHPPHP
Call US : 011-65164822
Add:- Block C 9/8, Sector-7, Rohini, Delhi -110085,
India
www.cpd-india.com www.blog.cpd-india.com
CPD TECHNOLOGIESCPD TECHNOLOGIES
Oops concepts in php
Topics to be covered
What is OOPS
Class & Objects
Modifier
Constructor
Deconstructor
Class Constants
Inheritance In Php
Magic Function
Polymorphism
Interfaces
Abstract Classes
Static Methods And Properties
Accessor Methods
Determining A Object's Class
What Is Oop ?
Object Oriented Programming (OOP) is the
programming method that involves the use of
the data , structure and organize classes of an
application. The data structure becomes an
objects that includes both functions and data. A
relationship between one object and other
object is created by the programmer
www.cpd-india.com
Classes
A class is a programmer
defined datatype which
include local fuctions as well
as local data.
Like a pattern or a blueprint
a oops class has exact
specifications. The
specification is the class' s
contract.
An object is a like a container that
contains methods and properties
which are require to make a certain
data types useful. An object’s
methods are what it can do and its
properties are what it knows.
Object
Modifier
Modifier
In object oriented programming, some
Keywords are private and some are public in
class. These keyword are known as modifier.
These keywords help you to define how these
variables and properties will be accessed by the
user of this class.
www.cpd-india.com
Modifier
Private: Properties or methods declared as
private are not allowed to be called from
outside the class. However any method inside
the same class can access them without a
problem. In our Emailer class we have all these
properties declared as private, so if we execute
the following code we will find an error.
www.cpd-india.com
Modifier
<?
include_once("class.emailer.php");
$emobject = new Emailer("hasin@somewherein.net");
$emobject->subject = "Hello world";
?>
The above code upon execution gives a fatal error as shown below:
<b>Faprivate property emailer::$subject
in <b>C:OOP with PHP5Codesch1class.emailer.php</b> on line
<b>43</><br />
tal error</b>: Cannot access That means you can't access
www.cpd-india.com
Modifier
Public: Any property or method which is not
explicitly declared as private or protected is a
public method. You can access a public method
from inside or outside the class.
Protected: This is another modifier which has a
special meaning in OOP. If any property or
method is declared as protected, you can only
access the method from its subclass. To see
how a protected method or property actually
works, we'll use the following example:
Modifier
To start, let's open class.emailer.php file (the
Emailer class) and change the declaration of the
$sender variable. Make it as follows:
protected $sender
Now create another file name
class.extendedemailer.php with the following
code: www.cpd-india.com
Modifier
<?
class ExtendedEmailer extends emailer
{
function __construct(){}
public function setSender($sender)
{
$this->sender = $sender;
}
}
?>
www.cpd-india.com
Constructor & Destructor
Constructor is Acclimated to Initialize the
Object.
Arguments can be taken by constructor.
A class name has same name as Constructor.
Memory allocation is done by Constructor.www.cpd-india.com
Constructor & Destructor
The objects that are created in memory, are
destroyed by the destructor.
Arguments can be taken by the destructor.
Overloading is possible in destructor.
It has same name as class name with tiled operator.
Class
Contants
Class Constants
You can make constants in your PHP scripts
utilizing the predefine keyword to define
(constant name, constant value). At the same
time to make constants in the class you need to
utilize the const keyword. These constants
really work like static variables, the main
distinction is that they are read-only.
www.cpd-india.com
Class Constants
<?
class WordCounter
{
const ASC=1; //you need not use $ sign before Constants
const DESC=2;
private $words;
function __construct($filename)
{
$file_content = file_get_contents($filename);
$this->words =
(array_count_values(str_word_count(strtolower
($file_content),1)));
www.cpd-india.com
Class Constants
}
public function count($order)
{
if ($order==self::ASC)
asort($this->words);
else if($order==self::DESC)
arsort($this->words);
foreach ($this->words as $key=>$val)
echo $key ." = ". $val."<br/>";
}
}
?>
www.cpd-india.com
Inheritance
Inheritance In Php
Inheritance is a well-known programming rule,
and PHP makes utilization of this standard in its
object model. This standard will influence the
way numerous objects and classes identify with
each other.
For illustration, when you extend a class, the
subclass inherits each public and protected
method from the guardian class. Unless a class
overrides those techniques, they will hold their
unique functionality
www.cpd-india.com
Inheritance
Magic Functions
Magic Functions
There are some predefine function names
which you can’t use in your programme unless
you have magic functionality relate with them.
These functions are known as Magic Functions.
Magic functions have special names which
begine with two underscores.
www.cpd-india.com
Magic Functions
_ _construct()
_ _deconstruct()
_ _call()
_ _callStatic()
_ _get()
_ _set()
_ _isset()
_ _unset()
__sleep()
__wakeup()
__tostring()
__invoke()
__ set_state()
__ clone()
__ debugInfo()
www.cpd-india.com
Magic Functions
_ _construct()
Construct function is called when object is
instantiated. Generally it is used in php 5 for
creating constructor
_ _deconstruct()
It is the opposite of construct function. When
object of a class is unset, this function is called.
www.cpd-india.com
Magic Functions
_ _call()
When a class in a function is try to call an
accessible or inaccessible function , this method
is called.
_ _callStatic()
It is similar to __callStatic() with only one
difference that is its triggered when you try to
call an accessible or inaccessible function in
static context.
www.cpd-india.com
Magic Functions
_ _get()
This function is triggered when your object try
call a variable of a class which is either
unavailable or inaccessible.
_ _set()
This function is called when we try to change to
value of a property which is unavailable or
inaccessible.
www.cpd-india.com
Polymorphism
www.cpd-india.com
Polymorphism
The ability of a object, variable or function to
appear in many form is known as
polymorphism. It allows a developer to
programme in general rather than programme
in specific. There are two types of
polymorphism.
compile time polymorphism
run-time polymorphism".
www.cpd-india.com
Interfaces
Interfaces
There are some specific set of variable and functions
which can be called outside a class itself. These are
known as interfaces. Interfaces are declared using
interface keyword.
<?
//interface.dbdriver.php
interface DBDriver
{
public function connect();
public function execute($sql);
}
?>
www.cpd-india.com
Abstract ClassesAbstract Classes
Abstract Classes
A class which is declared using abstract keyword is
known as abstract class. An abstract class is not
implemented just declared only (followed by
semicolon without braces)
<?
//abstract.reportgenerator.php
abstract class ReportGenerator
{
public function generateReport($resultArray)
{
//write code to process the multidimensional result array and
//generate HTML Report
}
}
? www.cpd-india.com
Static Method AndStatic Method And
PropertiesProperties
Static Methods & Properties
In object oriented programming, static keyword is
very crucial. Static properties and method acts as a
significant element in design pattern and application
design. To access any method or attribute in a class
you must create an instance (i.e. using new keyword,
like $object = new emailer()), otherwise you can't
access them. But there is a difference for static
methods and properties. You can access a static
method or property directly without creating any
instance of that class. A static member is like a global
member for that class and all instances of that class
Static Methods & Properties
<?
//class.dbmanager.php
class DBManager
{
public static function getMySQLDriver()
{
//instantiate a new MySQL Driver object and return
}
public static function getPostgreSQLDriver()
www.cpd-india.com
Static Methods & Properties
{
//instantiate a new PostgreSQL Driver object and
return
}
public static function getSQLiteDriver()
{
//instantiate a new MySQL Driver object and return
}
}
?>
www.cpd-india.com
AccessorAccessor
MethodMethod
Accessor Method
Accessor methods are simply methods that are
solely devoted to get and set the value of any class
properties. It's a good practice to access class
properties using accessor methods instead of
directly setting or getting their value. Though
accessor methods are the same as other methods,
there are some conventions writing them. There
are two types of accessor methods. One is called
getter, whose purpose is returning value of any
class property. The other is setter that sets a value
into a class property. www.cpd-india.com
Accessor Method
<?
class Student
{
private $name;
private $roll;
More free ebooks : http://fast-file.blogspot.com
Chapter 2
[ 39 ]
public function setName($name)
{
$this->name= $name;
} www.cpd-india.com
Accessor Method
public function setRoll($roll)
{
$this->roll =$roll;
}
public function getName()
{
return $this->name;
}
public function getRoll()
{
return $this->roll;
}
}
?>
www.cpd-india.com
Determining A Object's Class
public function setRoll($roll)
{
$this->roll =$roll;
}
public function getName()
{
return $this->name;
}
public function getRoll()
{
return $this->roll;
}
}
?>
www.cpd-india.com
CPD TECHNOLOGIES
Block C 9/8, Sector-7, Rohini, Delhi -110085
support@cpd-india.com

More Related Content

What's hot (20)

PPT
PHP - Introduction to PHP AJAX
Vibrant Technologies & Computers
 
PPTX
Ajax ppt - 32 slides
Smithss25
 
PPTX
Dom(document object model)
Partnered Health
 
PPT
Class 3 - PHP Functions
Ahmed Swilam
 
PDF
jQuery for beginners
Arulmurugan Rajaraman
 
PDF
Php introduction
krishnapriya Tadepalli
 
PPTX
Loops PHP 04
mohamedsaad24
 
PPT
C# Basics
Sunil OS
 
PPTX
Javascript operators
Mohit Rana
 
PPTX
JSON: The Basics
Jeff Fox
 
PPTX
Database Connectivity in PHP
Taha Malampatti
 
PDF
JavaScript - Chapter 11 - Events
WebStackAcademy
 
PPTX
Classes, objects in JAVA
Abhilash Nair
 
PPTX
Event In JavaScript
ShahDhruv21
 
PPT
Collection Framework in java
CPD INDIA
 
PPTX
Hibernate ppt
Aneega
 
PPTX
PHP slides
Farzad Wadia
 
PDF
JavaScript - Chapter 8 - Objects
WebStackAcademy
 
PPTX
PHP Form Validation Technique
Morshedul Arefin
 
PHP - Introduction to PHP AJAX
Vibrant Technologies & Computers
 
Ajax ppt - 32 slides
Smithss25
 
Dom(document object model)
Partnered Health
 
Class 3 - PHP Functions
Ahmed Swilam
 
jQuery for beginners
Arulmurugan Rajaraman
 
Php introduction
krishnapriya Tadepalli
 
Loops PHP 04
mohamedsaad24
 
C# Basics
Sunil OS
 
Javascript operators
Mohit Rana
 
JSON: The Basics
Jeff Fox
 
Database Connectivity in PHP
Taha Malampatti
 
JavaScript - Chapter 11 - Events
WebStackAcademy
 
Classes, objects in JAVA
Abhilash Nair
 
Event In JavaScript
ShahDhruv21
 
Collection Framework in java
CPD INDIA
 
Hibernate ppt
Aneega
 
PHP slides
Farzad Wadia
 
JavaScript - Chapter 8 - Objects
WebStackAcademy
 
PHP Form Validation Technique
Morshedul Arefin
 

Viewers also liked (20)

PPT
Oops in PHP
Mindfire Solutions
 
ODP
Beginners Guide to Object Orientation in PHP
Rick Ogden
 
PPTX
OOPS Characteristics (With Examples in PHP)
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
Object oriented programming in php 5
Sayed Ahmed
 
PPTX
Hibernate
CPD INDIA
 
PDF
Being functional in PHP
David de Boer
 
PPTX
Introduction to PHP OOP
fakhrul hasan
 
PPTX
What is SQL Server?
CPD INDIA
 
PPTX
Classes function overloading
ankush_kumar
 
PPTX
Object oreinted php | OOPs
Ravi Bhadauria
 
PPTX
PHP Functions & Arrays
Henry Osborne
 
PPT
Functions in php
Mudasir Syed
 
PPTX
Php oop presentation
Mutinda Boniface
 
PPTX
Document object model(dom)
rahul kundu
 
PPTX
Arrays &amp; functions in php
Ashish Chamoli
 
PDF
Javascript and DOM
Brian Moschel
 
DOC
Creating a Simple PHP and MySQL-Based Login System
Azharul Haque Shohan
 
PPTX
Php string function
Ravi Bhadauria
 
PPT
Document Object Model
chomas kandar
 
Oops in PHP
Mindfire Solutions
 
Beginners Guide to Object Orientation in PHP
Rick Ogden
 
OOPS Characteristics (With Examples in PHP)
baabtra.com - No. 1 supplier of quality freshers
 
Object oriented programming in php 5
Sayed Ahmed
 
Hibernate
CPD INDIA
 
Being functional in PHP
David de Boer
 
Introduction to PHP OOP
fakhrul hasan
 
What is SQL Server?
CPD INDIA
 
Classes function overloading
ankush_kumar
 
Object oreinted php | OOPs
Ravi Bhadauria
 
PHP Functions & Arrays
Henry Osborne
 
Functions in php
Mudasir Syed
 
Php oop presentation
Mutinda Boniface
 
Document object model(dom)
rahul kundu
 
Arrays &amp; functions in php
Ashish Chamoli
 
Javascript and DOM
Brian Moschel
 
Creating a Simple PHP and MySQL-Based Login System
Azharul Haque Shohan
 
Php string function
Ravi Bhadauria
 
Document Object Model
chomas kandar
 
Ad

Similar to Oops concepts in php (20)

PPTX
OOPS IN PHP.pptx
rani marri
 
PDF
Object_oriented_programming_OOP_with_PHP.pdf
GammingWorld2
 
PPT
Introduction to OOP with PHP
Michael Peacock
 
ZIP
Object Oriented PHP5
Jason Austin
 
PPTX
Php oop (1)
Sudip Simkhada
 
PPTX
Lecture-10_PHP-OOP.pptx
ShaownRoy1
 
PPTX
Object oriented programming in php
Aashiq Kuchey
 
PPT
Class 7 - PHP Object Oriented Programming
Ahmed Swilam
 
PDF
Demystifying Object-Oriented Programming #phpbnl18
Alena Holligan
 
PPTX
Chap4 oop class (php) part 1
monikadeshmane
 
PPT
Php object orientation and classes
Kumar
 
PPTX
Only oop
anitarooge
 
PDF
Object Oriented Programming in PHP
wahidullah mudaser
 
PPTX
PHP OOP Lecture - 02.pptx
Atikur Rahman
 
PPTX
Lecture 17 - PHP-Object-Orientation.pptx
DavidLazar17
 
PPTX
c91632a4-2e92-4edf-b750-358da15ed1b1.pptx
ajayparmeshwarmahaja
 
PPT
PHP-05-Objects.ppt
rani marri
 
DOCX
Oops concept in php
selvabalaji k
 
PPT
PHP- Introduction to Object Oriented PHP
Vibrant Technologies & Computers
 
PPTX
Ch8(oop)
Chhom Karath
 
OOPS IN PHP.pptx
rani marri
 
Object_oriented_programming_OOP_with_PHP.pdf
GammingWorld2
 
Introduction to OOP with PHP
Michael Peacock
 
Object Oriented PHP5
Jason Austin
 
Php oop (1)
Sudip Simkhada
 
Lecture-10_PHP-OOP.pptx
ShaownRoy1
 
Object oriented programming in php
Aashiq Kuchey
 
Class 7 - PHP Object Oriented Programming
Ahmed Swilam
 
Demystifying Object-Oriented Programming #phpbnl18
Alena Holligan
 
Chap4 oop class (php) part 1
monikadeshmane
 
Php object orientation and classes
Kumar
 
Only oop
anitarooge
 
Object Oriented Programming in PHP
wahidullah mudaser
 
PHP OOP Lecture - 02.pptx
Atikur Rahman
 
Lecture 17 - PHP-Object-Orientation.pptx
DavidLazar17
 
c91632a4-2e92-4edf-b750-358da15ed1b1.pptx
ajayparmeshwarmahaja
 
PHP-05-Objects.ppt
rani marri
 
Oops concept in php
selvabalaji k
 
PHP- Introduction to Object Oriented PHP
Vibrant Technologies & Computers
 
Ch8(oop)
Chhom Karath
 
Ad

Recently uploaded (20)

PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PPTX
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
PPTX
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 

Oops concepts in php

  • 1. OOPSOOPS -Concepts in-Concepts in PHPPHP Call US : 011-65164822 Add:- Block C 9/8, Sector-7, Rohini, Delhi -110085, India www.cpd-india.com www.blog.cpd-india.com CPD TECHNOLOGIESCPD TECHNOLOGIES
  • 3. Topics to be covered What is OOPS Class & Objects Modifier Constructor Deconstructor Class Constants Inheritance In Php Magic Function Polymorphism Interfaces Abstract Classes Static Methods And Properties Accessor Methods Determining A Object's Class
  • 4. What Is Oop ? Object Oriented Programming (OOP) is the programming method that involves the use of the data , structure and organize classes of an application. The data structure becomes an objects that includes both functions and data. A relationship between one object and other object is created by the programmer www.cpd-india.com
  • 5. Classes A class is a programmer defined datatype which include local fuctions as well as local data. Like a pattern or a blueprint a oops class has exact specifications. The specification is the class' s contract.
  • 6. An object is a like a container that contains methods and properties which are require to make a certain data types useful. An object’s methods are what it can do and its properties are what it knows. Object
  • 8. Modifier In object oriented programming, some Keywords are private and some are public in class. These keyword are known as modifier. These keywords help you to define how these variables and properties will be accessed by the user of this class. www.cpd-india.com
  • 9. Modifier Private: Properties or methods declared as private are not allowed to be called from outside the class. However any method inside the same class can access them without a problem. In our Emailer class we have all these properties declared as private, so if we execute the following code we will find an error. www.cpd-india.com
  • 10. Modifier <? include_once("class.emailer.php"); $emobject = new Emailer("[email protected]"); $emobject->subject = "Hello world"; ?> The above code upon execution gives a fatal error as shown below: <b>Faprivate property emailer::$subject in <b>C:OOP with PHP5Codesch1class.emailer.php</b> on line <b>43</><br /> tal error</b>: Cannot access That means you can't access www.cpd-india.com
  • 11. Modifier Public: Any property or method which is not explicitly declared as private or protected is a public method. You can access a public method from inside or outside the class. Protected: This is another modifier which has a special meaning in OOP. If any property or method is declared as protected, you can only access the method from its subclass. To see how a protected method or property actually works, we'll use the following example:
  • 12. Modifier To start, let's open class.emailer.php file (the Emailer class) and change the declaration of the $sender variable. Make it as follows: protected $sender Now create another file name class.extendedemailer.php with the following code: www.cpd-india.com
  • 13. Modifier <? class ExtendedEmailer extends emailer { function __construct(){} public function setSender($sender) { $this->sender = $sender; } } ?> www.cpd-india.com
  • 14. Constructor & Destructor Constructor is Acclimated to Initialize the Object. Arguments can be taken by constructor. A class name has same name as Constructor. Memory allocation is done by Constructor.www.cpd-india.com
  • 15. Constructor & Destructor The objects that are created in memory, are destroyed by the destructor. Arguments can be taken by the destructor. Overloading is possible in destructor. It has same name as class name with tiled operator.
  • 17. Class Constants You can make constants in your PHP scripts utilizing the predefine keyword to define (constant name, constant value). At the same time to make constants in the class you need to utilize the const keyword. These constants really work like static variables, the main distinction is that they are read-only. www.cpd-india.com
  • 18. Class Constants <? class WordCounter { const ASC=1; //you need not use $ sign before Constants const DESC=2; private $words; function __construct($filename) { $file_content = file_get_contents($filename); $this->words = (array_count_values(str_word_count(strtolower ($file_content),1))); www.cpd-india.com
  • 19. Class Constants } public function count($order) { if ($order==self::ASC) asort($this->words); else if($order==self::DESC) arsort($this->words); foreach ($this->words as $key=>$val) echo $key ." = ". $val."<br/>"; } } ?> www.cpd-india.com
  • 21. Inheritance In Php Inheritance is a well-known programming rule, and PHP makes utilization of this standard in its object model. This standard will influence the way numerous objects and classes identify with each other. For illustration, when you extend a class, the subclass inherits each public and protected method from the guardian class. Unless a class overrides those techniques, they will hold their unique functionality www.cpd-india.com
  • 24. Magic Functions There are some predefine function names which you can’t use in your programme unless you have magic functionality relate with them. These functions are known as Magic Functions. Magic functions have special names which begine with two underscores. www.cpd-india.com
  • 25. Magic Functions _ _construct() _ _deconstruct() _ _call() _ _callStatic() _ _get() _ _set() _ _isset() _ _unset() __sleep() __wakeup() __tostring() __invoke() __ set_state() __ clone() __ debugInfo() www.cpd-india.com
  • 26. Magic Functions _ _construct() Construct function is called when object is instantiated. Generally it is used in php 5 for creating constructor _ _deconstruct() It is the opposite of construct function. When object of a class is unset, this function is called. www.cpd-india.com
  • 27. Magic Functions _ _call() When a class in a function is try to call an accessible or inaccessible function , this method is called. _ _callStatic() It is similar to __callStatic() with only one difference that is its triggered when you try to call an accessible or inaccessible function in static context. www.cpd-india.com
  • 28. Magic Functions _ _get() This function is triggered when your object try call a variable of a class which is either unavailable or inaccessible. _ _set() This function is called when we try to change to value of a property which is unavailable or inaccessible. www.cpd-india.com
  • 30. Polymorphism The ability of a object, variable or function to appear in many form is known as polymorphism. It allows a developer to programme in general rather than programme in specific. There are two types of polymorphism. compile time polymorphism run-time polymorphism". www.cpd-india.com
  • 32. Interfaces There are some specific set of variable and functions which can be called outside a class itself. These are known as interfaces. Interfaces are declared using interface keyword. <? //interface.dbdriver.php interface DBDriver { public function connect(); public function execute($sql); } ?> www.cpd-india.com
  • 34. Abstract Classes A class which is declared using abstract keyword is known as abstract class. An abstract class is not implemented just declared only (followed by semicolon without braces) <? //abstract.reportgenerator.php abstract class ReportGenerator { public function generateReport($resultArray) { //write code to process the multidimensional result array and //generate HTML Report } } ? www.cpd-india.com
  • 35. Static Method AndStatic Method And PropertiesProperties
  • 36. Static Methods & Properties In object oriented programming, static keyword is very crucial. Static properties and method acts as a significant element in design pattern and application design. To access any method or attribute in a class you must create an instance (i.e. using new keyword, like $object = new emailer()), otherwise you can't access them. But there is a difference for static methods and properties. You can access a static method or property directly without creating any instance of that class. A static member is like a global member for that class and all instances of that class
  • 37. Static Methods & Properties <? //class.dbmanager.php class DBManager { public static function getMySQLDriver() { //instantiate a new MySQL Driver object and return } public static function getPostgreSQLDriver() www.cpd-india.com
  • 38. Static Methods & Properties { //instantiate a new PostgreSQL Driver object and return } public static function getSQLiteDriver() { //instantiate a new MySQL Driver object and return } } ?> www.cpd-india.com
  • 40. Accessor Method Accessor methods are simply methods that are solely devoted to get and set the value of any class properties. It's a good practice to access class properties using accessor methods instead of directly setting or getting their value. Though accessor methods are the same as other methods, there are some conventions writing them. There are two types of accessor methods. One is called getter, whose purpose is returning value of any class property. The other is setter that sets a value into a class property. www.cpd-india.com
  • 41. Accessor Method <? class Student { private $name; private $roll; More free ebooks : http://fast-file.blogspot.com Chapter 2 [ 39 ] public function setName($name) { $this->name= $name; } www.cpd-india.com
  • 42. Accessor Method public function setRoll($roll) { $this->roll =$roll; } public function getName() { return $this->name; } public function getRoll() { return $this->roll; } } ?> www.cpd-india.com
  • 43. Determining A Object's Class public function setRoll($roll) { $this->roll =$roll; } public function getName() { return $this->name; } public function getRoll() { return $this->roll; } } ?> www.cpd-india.com
  • 44. CPD TECHNOLOGIES Block C 9/8, Sector-7, Rohini, Delhi -110085 [email protected]