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
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

Object oreinted php | OOPs
Object oreinted php | OOPsObject oreinted php | OOPs
Object oreinted php | OOPs
Ravi Bhadauria
 
Php Tutorials for Beginners
Php Tutorials for BeginnersPhp Tutorials for Beginners
Php Tutorials for Beginners
Vineet Kumar Saini
 
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
Vibrant Technologies & Computers
 
PHP Loops and PHP Forms
PHP  Loops and PHP FormsPHP  Loops and PHP Forms
PHP Loops and PHP Forms
M.Zalmai Rahmani
 
Php oop presentation
Php   oop presentationPhp   oop presentation
Php oop presentation
Mutinda Boniface
 
JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
WebStackAcademy
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
wahidullah mudaser
 
PHP FUNCTIONS
PHP FUNCTIONSPHP FUNCTIONS
PHP FUNCTIONS
Zeeshan Ahmed
 
JavaScript & Dom Manipulation
JavaScript & Dom ManipulationJavaScript & Dom Manipulation
JavaScript & Dom Manipulation
Mohammed Arif
 
Statements and Conditions in PHP
Statements and Conditions in PHPStatements and Conditions in PHP
Statements and Conditions in PHP
Maruf Abdullah (Rion)
 
PHP variables
PHP  variablesPHP  variables
PHP variables
Siddique Ibrahim
 
Php string function
Php string function Php string function
Php string function
Ravi Bhadauria
 
Class 3 - PHP Functions
Class 3 - PHP FunctionsClass 3 - PHP Functions
Class 3 - PHP Functions
Ahmed Swilam
 
PHP - Introduction to File Handling with PHP
PHP -  Introduction to  File Handling with PHPPHP -  Introduction to  File Handling with PHP
PHP - Introduction to File Handling with PHP
Vibrant Technologies & Computers
 
MYSQL - PHP Database Connectivity
MYSQL - PHP Database ConnectivityMYSQL - PHP Database Connectivity
MYSQL - PHP Database Connectivity
V.V.Vanniaperumal College for Women
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
pratik tambekar
 
JavaScript - Chapter 6 - Basic Functions
 JavaScript - Chapter 6 - Basic Functions JavaScript - Chapter 6 - Basic Functions
JavaScript - Chapter 6 - Basic Functions
WebStackAcademy
 
Php forms
Php formsPhp forms
Php forms
Anne Lee
 

What's hot (20)

Object oreinted php | OOPs
Object oreinted php | OOPsObject oreinted php | OOPs
Object oreinted php | OOPs
 
Php Tutorials for Beginners
Php Tutorials for BeginnersPhp Tutorials for Beginners
Php Tutorials for Beginners
 
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
 
PHP Loops and PHP Forms
PHP  Loops and PHP FormsPHP  Loops and PHP Forms
PHP Loops and PHP Forms
 
Php oop presentation
Php   oop presentationPhp   oop presentation
Php oop presentation
 
JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
 
Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
 
PHP FUNCTIONS
PHP FUNCTIONSPHP FUNCTIONS
PHP FUNCTIONS
 
JavaScript & Dom Manipulation
JavaScript & Dom ManipulationJavaScript & Dom Manipulation
JavaScript & Dom Manipulation
 
Statements and Conditions in PHP
Statements and Conditions in PHPStatements and Conditions in PHP
Statements and Conditions in PHP
 
PHP variables
PHP  variablesPHP  variables
PHP variables
 
Php string function
Php string function Php string function
Php string function
 
Class 3 - PHP Functions
Class 3 - PHP FunctionsClass 3 - PHP Functions
Class 3 - PHP Functions
 
PHP - Introduction to File Handling with PHP
PHP -  Introduction to  File Handling with PHPPHP -  Introduction to  File Handling with PHP
PHP - Introduction to File Handling with PHP
 
MYSQL - PHP Database Connectivity
MYSQL - PHP Database ConnectivityMYSQL - PHP Database Connectivity
MYSQL - PHP Database Connectivity
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
JavaScript - Chapter 6 - Basic Functions
 JavaScript - Chapter 6 - Basic Functions JavaScript - Chapter 6 - Basic Functions
JavaScript - Chapter 6 - Basic Functions
 
MVC in PHP
MVC in PHPMVC in PHP
MVC in PHP
 
Php forms
Php formsPhp forms
Php forms
 
GET and POST in PHP
GET and POST in PHPGET and POST in PHP
GET and POST in PHP
 

Viewers also liked

PHP Classes and OOPS Concept
PHP Classes and OOPS ConceptPHP Classes and OOPS Concept
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
Rick Ogden
 
OOPS Characteristics (With Examples in PHP)
OOPS Characteristics (With Examples in PHP)OOPS Characteristics (With Examples in PHP)
OOPS Characteristics (With Examples in PHP)
baabtra.com - No. 1 supplier of quality freshers
 
Object oriented programming in php 5
Object oriented programming in php 5Object oriented programming in php 5
Object oriented programming in php 5
Sayed Ahmed
 
Being functional in PHP
Being functional in PHPBeing functional in PHP
Being functional in PHP
David de Boer
 
Introduction to PHP OOP
Introduction to PHP OOPIntroduction to PHP OOP
Introduction to PHP OOP
fakhrul hasan
 
What is SQL Server?
What is SQL Server?What is SQL Server?
What is SQL Server?
CPD INDIA
 
Classes function overloading
Classes function overloadingClasses function overloading
Classes function overloadingankush_kumar
 
PHP Functions & Arrays
PHP Functions & ArraysPHP Functions & Arrays
PHP Functions & Arrays
Henry Osborne
 
Functions in php
Functions in phpFunctions in php
Functions in php
Mudasir Syed
 
Document object model(dom)
Document object model(dom)Document object model(dom)
Document object model(dom)
rahul kundu
 
Arrays &amp; functions in php
Arrays &amp; functions in phpArrays &amp; functions in php
Arrays &amp; functions in php
Ashish Chamoli
 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in java
CPD INDIA
 
Javascript and DOM
Javascript and DOMJavascript and DOM
Javascript and DOM
Brian Moschel
 
Creating a Simple PHP and MySQL-Based Login System
Creating a Simple PHP and MySQL-Based Login SystemCreating a Simple PHP and MySQL-Based Login System
Creating a Simple PHP and MySQL-Based Login SystemAzharul Haque Shohan
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Modelchomas kandar
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
CPD INDIA
 

Viewers also liked (18)

PHP Classes and OOPS Concept
PHP Classes and OOPS ConceptPHP Classes and OOPS Concept
PHP Classes and OOPS Concept
 
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
 
OOPS Characteristics (With Examples in PHP)
OOPS Characteristics (With Examples in PHP)OOPS Characteristics (With Examples in PHP)
OOPS Characteristics (With Examples in PHP)
 
Object oriented programming in php 5
Object oriented programming in php 5Object oriented programming in php 5
Object oriented programming in php 5
 
Hibernate
HibernateHibernate
Hibernate
 
Being functional in PHP
Being functional in PHPBeing functional in PHP
Being functional in PHP
 
Introduction to PHP OOP
Introduction to PHP OOPIntroduction to PHP OOP
Introduction to PHP OOP
 
What is SQL Server?
What is SQL Server?What is SQL Server?
What is SQL Server?
 
Classes function overloading
Classes function overloadingClasses function overloading
Classes function overloading
 
PHP Functions & Arrays
PHP Functions & ArraysPHP Functions & Arrays
PHP Functions & Arrays
 
Functions in php
Functions in phpFunctions in php
Functions in php
 
Document object model(dom)
Document object model(dom)Document object model(dom)
Document object model(dom)
 
Arrays &amp; functions in php
Arrays &amp; functions in phpArrays &amp; functions in php
Arrays &amp; functions in php
 
Collection Framework in java
Collection Framework in javaCollection Framework in java
Collection Framework in java
 
Javascript and DOM
Javascript and DOMJavascript and DOM
Javascript and DOM
 
Creating a Simple PHP and MySQL-Based Login System
Creating a Simple PHP and MySQL-Based Login SystemCreating a Simple PHP and MySQL-Based Login System
Creating a Simple PHP and MySQL-Based Login System
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Model
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
 

Similar to Oops concepts in php

OOPS IN PHP.pptx
OOPS IN PHP.pptxOOPS IN PHP.pptx
OOPS IN PHP.pptx
rani marri
 
Only oop
Only oopOnly oop
Only oop
anitarooge
 
Introduction to OOP with PHP
Introduction to OOP with PHPIntroduction to OOP with PHP
Introduction to OOP with PHPMichael Peacock
 
Introduction Php
Introduction PhpIntroduction Php
Introduction Php
sanjay joshi
 
Basic Oops concept of PHP
Basic Oops concept of PHPBasic Oops concept of PHP
Basic Oops concept of PHP
Rohan Sharma
 
Oops in php
Oops in phpOops in php
Oops in php
sanjay joshi
 
Php oop (1)
Php oop (1)Php oop (1)
Php oop (1)
Sudip Simkhada
 
PHP OOP Lecture - 02.pptx
PHP OOP Lecture - 02.pptxPHP OOP Lecture - 02.pptx
PHP OOP Lecture - 02.pptx
Atikur Rahman
 
Object_oriented_programming_OOP_with_PHP.pdf
Object_oriented_programming_OOP_with_PHP.pdfObject_oriented_programming_OOP_with_PHP.pdf
Object_oriented_programming_OOP_with_PHP.pdf
GammingWorld2
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
akreyi
 
Object oriented programming in php
Object oriented programming in phpObject oriented programming in php
Object oriented programming in php
Aashiq Kuchey
 
Lecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptxLecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptx
ShaownRoy1
 
Oop features java presentationshow
Oop features java presentationshowOop features java presentationshow
Oop features java presentationshow
ilias ahmed
 
Application package
Application packageApplication package
Application packageJAYAARC
 
Synapseindia object oriented programming in php
Synapseindia object oriented programming in phpSynapseindia object oriented programming in php
Synapseindia object oriented programming in php
Synapseindiappsdevelopment
 
Advanced php
Advanced phpAdvanced php
Advanced phphamfu
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented Programming
Ahmed Swilam
 
Object Oriented PHP5
Object Oriented PHP5Object Oriented PHP5
Object Oriented PHP5
Jason Austin
 
Object Oriented Javascript part2
Object Oriented Javascript part2Object Oriented Javascript part2
Object Oriented Javascript part2
Usman Mehmood
 
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering CollegeObject Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Dhivyaa C.R
 

Similar to Oops concepts in php (20)

OOPS IN PHP.pptx
OOPS IN PHP.pptxOOPS IN PHP.pptx
OOPS IN PHP.pptx
 
Only oop
Only oopOnly oop
Only oop
 
Introduction to OOP with PHP
Introduction to OOP with PHPIntroduction to OOP with PHP
Introduction to OOP with PHP
 
Introduction Php
Introduction PhpIntroduction Php
Introduction Php
 
Basic Oops concept of PHP
Basic Oops concept of PHPBasic Oops concept of PHP
Basic Oops concept of PHP
 
Oops in php
Oops in phpOops in php
Oops in php
 
Php oop (1)
Php oop (1)Php oop (1)
Php oop (1)
 
PHP OOP Lecture - 02.pptx
PHP OOP Lecture - 02.pptxPHP OOP Lecture - 02.pptx
PHP OOP Lecture - 02.pptx
 
Object_oriented_programming_OOP_with_PHP.pdf
Object_oriented_programming_OOP_with_PHP.pdfObject_oriented_programming_OOP_with_PHP.pdf
Object_oriented_programming_OOP_with_PHP.pdf
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
Object oriented programming in php
Object oriented programming in phpObject oriented programming in php
Object oriented programming in php
 
Lecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptxLecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptx
 
Oop features java presentationshow
Oop features java presentationshowOop features java presentationshow
Oop features java presentationshow
 
Application package
Application packageApplication package
Application package
 
Synapseindia object oriented programming in php
Synapseindia object oriented programming in phpSynapseindia object oriented programming in php
Synapseindia object oriented programming in php
 
Advanced php
Advanced phpAdvanced php
Advanced php
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented Programming
 
Object Oriented PHP5
Object Oriented PHP5Object Oriented PHP5
Object Oriented PHP5
 
Object Oriented Javascript part2
Object Oriented Javascript part2Object Oriented Javascript part2
Object Oriented Javascript part2
 
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering CollegeObject Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
 

Recently uploaded

Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
Nguyen Thanh Tu Collection
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 

Recently uploaded (20)

Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 

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
  • 2.
  • 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("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
  • 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 support@cpd-india.com