SlideShare a Scribd company logo
1 of 39
OOPS IN PHP
By
Dr M.RANI REDDY
Topics
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
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.
Creating a class
<?php
Class emailer
{
Private $sender;
Private $receiver;
}
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
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.
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.
Modifier
<?
include_once("class.emailer.php");
$emobject = new Emailer("mranimca@rediff.com");
$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
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:
Modifier
<?
class ExtendedEmailer extends emailer
{
function construct(){}
public function setSender($sender)
{
$this->sender = $sender;
}
}
?>
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
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.
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)));
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/>";
}
}
?>
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
Inheritance
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.
Magic Functions
_ _construct()
_ _deconstruct()
_ _call()
_ _callStatic()
_ _get()
_ _set()
_ _isset()
_ _unset()
sleep()
wakeup()
tostring()
invoke()
set_state()
clone()
debugInfo()
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.
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.
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.
Polymorphism
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".
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);
}
?>
Abstract 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
}
}
?
Static Method And
Properties
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()
Static Methods & Properties
{
//instantiate a new PostgreSQL Driver object and
return
}
public static function getSQLiteDriver()
{
//instantiate a new MySQL Driver object and return
}
}
?>
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.
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;
}
Accessor Method
public function setRoll($roll)
{
$this->roll =$roll;
}
public function getName()
{
return $this->name;
}
public function getRoll()
{
return $this->roll;
}
}
?>
Determining A Object's Class
public function setRoll($roll)
{
$this->roll =$roll;
}
public function getName()
{
return $this->name;
}
public function getRoll()
{
return $this->roll;
}
}
?>

More Related Content

Similar to OOPS IN PHP.pptx

Jedi slides 2.1 object-oriented concepts
Jedi slides 2.1 object-oriented conceptsJedi slides 2.1 object-oriented concepts
Jedi slides 2.1 object-oriented conceptsMaryo Manjaruni
 
Beginners Guide to Object Orientation in PHP
Beginners Guide to Object Orientation in PHPBeginners Guide to Object Orientation in PHP
Beginners Guide to Object Orientation in PHPRick Ogden
 
Object Oriented Javascript part2
Object Oriented Javascript part2Object Oriented Javascript part2
Object Oriented Javascript part2Usman Mehmood
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingAhmed Swilam
 
JavaScript OOPS Implimentation
JavaScript OOPS ImplimentationJavaScript OOPS Implimentation
JavaScript OOPS ImplimentationUsman Mehmood
 
oops-123991513147-phpapp02.pdf
oops-123991513147-phpapp02.pdfoops-123991513147-phpapp02.pdf
oops-123991513147-phpapp02.pdfArpitaJana28
 
PHP - Introduction to Object Oriented Programming with PHP
PHP -  Introduction to  Object Oriented Programming with PHPPHP -  Introduction to  Object Oriented Programming with PHP
PHP - Introduction to Object Oriented Programming with PHPVibrant Technologies & Computers
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorialsakreyi
 
(An Extended) Beginners Guide to Object Orientation in PHP
(An Extended) Beginners Guide to Object Orientation in PHP(An Extended) Beginners Guide to Object Orientation in PHP
(An Extended) Beginners Guide to Object Orientation in PHPRick Ogden
 
Object Oriented PHP - PART-1
Object Oriented PHP - PART-1Object Oriented PHP - PART-1
Object Oriented PHP - PART-1Jalpesh Vasa
 
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...AnkurSingh340457
 
Object oriented programming in php
Object oriented programming in phpObject oriented programming in php
Object oriented programming in phpAashiq Kuchey
 
Basic Oops concept of PHP
Basic Oops concept of PHPBasic Oops concept of PHP
Basic Oops concept of PHPRohan Sharma
 
Abap object-oriented-programming-tutorials
Abap object-oriented-programming-tutorialsAbap object-oriented-programming-tutorials
Abap object-oriented-programming-tutorialscesarmendez78
 
Object oriented basics
Object oriented basicsObject oriented basics
Object oriented basicsvamshimahi
 

Similar to OOPS IN PHP.pptx (20)

Jedi slides 2.1 object-oriented concepts
Jedi slides 2.1 object-oriented conceptsJedi slides 2.1 object-oriented concepts
Jedi slides 2.1 object-oriented concepts
 
Beginners Guide to Object Orientation in PHP
Beginners Guide to Object Orientation in PHPBeginners Guide to Object Orientation in PHP
Beginners Guide to Object Orientation in PHP
 
Object Oriented Javascript part2
Object Oriented Javascript part2Object Oriented Javascript part2
Object Oriented Javascript part2
 
My c++
My c++My c++
My c++
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented Programming
 
JavaScript OOPS Implimentation
JavaScript OOPS ImplimentationJavaScript OOPS Implimentation
JavaScript OOPS Implimentation
 
oops-123991513147-phpapp02.pdf
oops-123991513147-phpapp02.pdfoops-123991513147-phpapp02.pdf
oops-123991513147-phpapp02.pdf
 
Oops
OopsOops
Oops
 
PHP - Introduction to Object Oriented Programming with PHP
PHP -  Introduction to  Object Oriented Programming with PHPPHP -  Introduction to  Object Oriented Programming with PHP
PHP - Introduction to Object Oriented Programming with PHP
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
(An Extended) Beginners Guide to Object Orientation in PHP
(An Extended) Beginners Guide to Object Orientation in PHP(An Extended) Beginners Guide to Object Orientation in PHP
(An Extended) Beginners Guide to Object Orientation in PHP
 
Object Oriented PHP - PART-1
Object Oriented PHP - PART-1Object Oriented PHP - PART-1
Object Oriented PHP - PART-1
 
Introduction Php
Introduction PhpIntroduction Php
Introduction Php
 
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
 
Object oriented programming in php
Object oriented programming in phpObject oriented programming in php
Object oriented programming in php
 
Lab 4 (1).pdf
Lab 4 (1).pdfLab 4 (1).pdf
Lab 4 (1).pdf
 
oopusingc.pptx
oopusingc.pptxoopusingc.pptx
oopusingc.pptx
 
Basic Oops concept of PHP
Basic Oops concept of PHPBasic Oops concept of PHP
Basic Oops concept of PHP
 
Abap object-oriented-programming-tutorials
Abap object-oriented-programming-tutorialsAbap object-oriented-programming-tutorials
Abap object-oriented-programming-tutorials
 
Object oriented basics
Object oriented basicsObject oriented basics
Object oriented basics
 

More from rani marri

NAAC PPT M.B.A.pptx
NAAC PPT M.B.A.pptxNAAC PPT M.B.A.pptx
NAAC PPT M.B.A.pptxrani marri
 
oops with java modules iii & iv.pptx
oops with java modules iii & iv.pptxoops with java modules iii & iv.pptx
oops with java modules iii & iv.pptxrani marri
 
oops with java modules i & ii.ppt
oops with java modules i & ii.pptoops with java modules i & ii.ppt
oops with java modules i & ii.pptrani marri
 
software engineering modules iii & iv.pptx
software engineering  modules iii & iv.pptxsoftware engineering  modules iii & iv.pptx
software engineering modules iii & iv.pptxrani marri
 
software engineering module i & ii.pptx
software engineering module i & ii.pptxsoftware engineering module i & ii.pptx
software engineering module i & ii.pptxrani marri
 
ADVANCED JAVA MODULE III & IV.ppt
ADVANCED JAVA MODULE III & IV.pptADVANCED JAVA MODULE III & IV.ppt
ADVANCED JAVA MODULE III & IV.pptrani marri
 
ADVANCED JAVA MODULE I & II.ppt
ADVANCED JAVA MODULE I & II.pptADVANCED JAVA MODULE I & II.ppt
ADVANCED JAVA MODULE I & II.pptrani marri
 
data structures module III & IV.pptx
data structures module III & IV.pptxdata structures module III & IV.pptx
data structures module III & IV.pptxrani marri
 
data structures module I & II.pptx
data structures module I & II.pptxdata structures module I & II.pptx
data structures module I & II.pptxrani marri
 
php programming.pptx
php programming.pptxphp programming.pptx
php programming.pptxrani marri
 
J2EEFeb11 (1).ppt
J2EEFeb11 (1).pptJ2EEFeb11 (1).ppt
J2EEFeb11 (1).pptrani marri
 
CODING QUESTIONS.pptx
CODING QUESTIONS.pptxCODING QUESTIONS.pptx
CODING QUESTIONS.pptxrani marri
 
12-OO-PHP.pptx
12-OO-PHP.pptx12-OO-PHP.pptx
12-OO-PHP.pptxrani marri
 
PHP-05-Objects.ppt
PHP-05-Objects.pptPHP-05-Objects.ppt
PHP-05-Objects.pptrani marri
 

More from rani marri (17)

NAAC PPT M.B.A.pptx
NAAC PPT M.B.A.pptxNAAC PPT M.B.A.pptx
NAAC PPT M.B.A.pptx
 
must.pptx
must.pptxmust.pptx
must.pptx
 
node.js.pptx
node.js.pptxnode.js.pptx
node.js.pptx
 
oops with java modules iii & iv.pptx
oops with java modules iii & iv.pptxoops with java modules iii & iv.pptx
oops with java modules iii & iv.pptx
 
oops with java modules i & ii.ppt
oops with java modules i & ii.pptoops with java modules i & ii.ppt
oops with java modules i & ii.ppt
 
software engineering modules iii & iv.pptx
software engineering  modules iii & iv.pptxsoftware engineering  modules iii & iv.pptx
software engineering modules iii & iv.pptx
 
software engineering module i & ii.pptx
software engineering module i & ii.pptxsoftware engineering module i & ii.pptx
software engineering module i & ii.pptx
 
ADVANCED JAVA MODULE III & IV.ppt
ADVANCED JAVA MODULE III & IV.pptADVANCED JAVA MODULE III & IV.ppt
ADVANCED JAVA MODULE III & IV.ppt
 
ADVANCED JAVA MODULE I & II.ppt
ADVANCED JAVA MODULE I & II.pptADVANCED JAVA MODULE I & II.ppt
ADVANCED JAVA MODULE I & II.ppt
 
data structures module III & IV.pptx
data structures module III & IV.pptxdata structures module III & IV.pptx
data structures module III & IV.pptx
 
data structures module I & II.pptx
data structures module I & II.pptxdata structures module I & II.pptx
data structures module I & II.pptx
 
php programming.pptx
php programming.pptxphp programming.pptx
php programming.pptx
 
NodeJS.ppt
NodeJS.pptNodeJS.ppt
NodeJS.ppt
 
J2EEFeb11 (1).ppt
J2EEFeb11 (1).pptJ2EEFeb11 (1).ppt
J2EEFeb11 (1).ppt
 
CODING QUESTIONS.pptx
CODING QUESTIONS.pptxCODING QUESTIONS.pptx
CODING QUESTIONS.pptx
 
12-OO-PHP.pptx
12-OO-PHP.pptx12-OO-PHP.pptx
12-OO-PHP.pptx
 
PHP-05-Objects.ppt
PHP-05-Objects.pptPHP-05-Objects.ppt
PHP-05-Objects.ppt
 

Recently uploaded

KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 

Recently uploaded (20)

Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 

OOPS IN PHP.pptx

  • 1. OOPS IN PHP By Dr M.RANI REDDY
  • 2. Topics 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
  • 3. 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
  • 4. 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.
  • 5. Creating a class <?php Class emailer { Private $sender; Private $receiver; }
  • 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
  • 7. 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.
  • 8. 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.
  • 9. Modifier <? include_once("class.emailer.php"); $emobject = new Emailer("mranimca@rediff.com"); $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
  • 10. 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:
  • 11. 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:
  • 12. Modifier <? class ExtendedEmailer extends emailer { function construct(){} public function setSender($sender) { $this->sender = $sender; } } ?>
  • 13. 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
  • 14. 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.
  • 16. 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.
  • 17. 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)));
  • 18. 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/>"; } } ?>
  • 20. 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
  • 22. 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.
  • 23. Magic Functions _ _construct() _ _deconstruct() _ _call() _ _callStatic() _ _get() _ _set() _ _isset() _ _unset() sleep() wakeup() tostring() invoke() set_state() clone() debugInfo()
  • 24. 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.
  • 25. 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.
  • 26. 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.
  • 28. 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".
  • 29. 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); } ?>
  • 31. 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 } } ?
  • 33. 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
  • 34. Static Methods & Properties <? //class.dbmanager.php class DBManager { public static function getMySQLDriver() { //instantiate a new MySQL Driver object and return } public static function getPostgreSQLDriver()
  • 35. Static Methods & Properties { //instantiate a new PostgreSQL Driver object and return } public static function getSQLiteDriver() { //instantiate a new MySQL Driver object and return } } ?>
  • 36. 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.
  • 37. 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; }
  • 38. Accessor Method public function setRoll($roll) { $this->roll =$roll; } public function getName() { return $this->name; } public function getRoll() { return $this->roll; } } ?>
  • 39. Determining A Object's Class public function setRoll($roll) { $this->roll =$roll; } public function getName() { return $this->name; } public function getRoll() { return $this->roll; } } ?>