SlideShare a Scribd company logo
1 of 29
A Presentation by 
ADMEC Multimedia Institute & Web Development Institute (WDI) Delhi 
Twitter: @admecinstitute 
www.admecindia.co.in 
www.web-development-institute.com
 The purpose of this PHP presentation is to explain 
Object Oriented PHP in brief. 
 This PHP presentation can help a PHP programmer 
in understanding the terms and terminologies used 
in practical object oriented PHP. 
 Frameworks of PHP like CodeIgniter, CakePHP, 
Symphony, Zend etc are MVC based and knowledge 
of Object Oriented PHP will help in understanding 
all them. 
www.admecindia.co.in 
www.web-development-institute.com
 Basics of OOP in PHP 
 Object & Classes in OOP 
 Magic Function in PHP OOP 
 Inheritance (Extending a class) 
 Visibility (public, private, protected) 
 Abstract Classes in PHP 
 Static Methods and properties in PHP 
 Interfaces in PHP 
 Explaining PHP Class Functions 
 Describing Autoload in PHP 
www.admecindia.co.in 
www.web-development-institute.com
 PHP is a scripting language 
 Specially a Procedural Programming 
 Not a true OO Programming 
 It supports few OO features 
 Full OOP Support added as of PHP5
 It is Object Oriented Programming method of 
coding. 
 Allow developer to group multiple similar 
tasks into classes. 
 The main aim of OOP is to not repeat the 
similar code again and again. 
 With OOP, it is easy to maintain the structure 
of application and organizing the data 
 OOP provide simplicity to the complex 
applications code. 
www.admecindia.co.in 
www.web-development-institute.com
 Code organization and maintainability 
 Add clarity 
 Reduce complexity 
 Simple rules allow complex interactions 
 Emphasizes data over procedure 
 Code modularity or refactoring 
 Code reusability 
 Well-suited for databases
 It depends 
 My PHP OOP rule of thumb 
◦ For a simple site, OOP adds unnecessary complexity 
◦ For a complex site, OOP adds necessary simplicity
Concept of classes & objects can be 
explained with these two images: 
 A class, for example, is like a blueprint for a 
house. It defines the shape of the house on 
paper, with relationships between the different 
parts of the house clearly defined and planned 
out, even though the house doesn't exist. 
 An object, then, is like the actual house built 
according to that blueprint. The data stored in 
the object is like the wood, wires, and 
concrete that compose the house: without 
being assembled according to the blueprint, 
it's just a pile of stuff. However, when it all 
comes together, it becomes an organized, 
useful house. 
www.admecindia.co.in 
www.web-development-institute.com
In PHP class is created using class keyword as shown in the 
following example 
class myOwnClass 
{ 
//variables of the class 
var $variable1; 
var $variable2; 
//Function of class 
function mergeVariable() 
{ 
return $this->variable1 . $this->variable2; 
} 
} 
www.admecindia.co.in 
www.web-development-institute.com
There is no use of classes without objects. Object is representative 
of your class. If created a class then you must need to create object 
of the class to solve your problem using class. You can create object 
of your class by using new keyword. 
$objClass = new myClass(); 
Now in above code you are creating object of class myClass in 
variable $objClass. You can create multiple object of your same 
class. Every object is different from other. 
$objClass1 = new myClass(); 
$objClass2 = new myClass(); 
www.admecindia.co.in 
www.web-development-institute.com
Magic methods in php are some predefined function by php 
compiler which executes on some event. Magic methods starts with 
prefix __, for example __call, __get, __set. 
List of Magic Functions in PHP 
__construct 
This magic methods is called when 
someone create object of your class. 
Usually this is used for creating 
constructor in php5. 
__destruct 
This magic method is called when object 
of your class is unset. This is just 
opposite of __construct. 
www.admecindia.co.in 
www.web-development-institute.com
__get 
This method called when your object 
attempt to read property or variable of the 
class which is inaccessible or unavailable. 
__set 
This method called when object of your 
class attempts to set value of the property 
which is really inaccessible or 
unavailable in your class. 
__isset 
This magic methods trigger when isset() 
function is applied on any property of the 
class which is inaccessible or unavailable. 
__unset 
__unset is something opposite of isset 
method. This method triggers when 
unset() function called on inaccessible or 
unavailable property of the class. 
www.admecindia.co.in 
www.web-development-institute.com
__call 
__call magic method trigger when you are 
attempting to call method or function of 
the class which is either inaccessible or 
unavailable. 
__callstatic 
__callstatic execture when inaccessible or 
unavailable method is in static context. 
__sleep 
__sleep methods trigger when you are 
going to serialize your class object. 
__wakeup 
__wakeup executes when you are 
un serializing any class object. 
www.admecindia.co.in 
www.web-development-institute.com
There are 3 type of visibility available in PHP for controlling 
your property or method. 
 Public: Public method or variable can be accessible from 
anywhere. I mean from inside the class, out side the class and 
in child(will discuss in next chapter) class also. 
 Private: Method or property with private visibility can only be 
accessible inside the class. You can not access private 
method or variable from outside of your class. 
 Protected: Method or variable with protected visibility can 
only be access in the derived class. Or in other word in child 
class. Protected will be used in the process of inheritance. 
www.admecindia.co.in 
www.web-development-institute.com
 The abstract classes and methods are used to create a model 
of minimum required methods which must be defined in 
normal sub-classes derived from an abstract class (with 
extends). 
 An abstract class is created with the abstract keyword. 
 An abstract class cannot be instantiated, can only be 
inherited by other sub-classes extended from it. 
 The abstract methods are declared with the abstract keyword, 
and cannot have an implementation, they simply declare the 
method's signature. abstract public function method 
Name($arguments); 
www.admecindia.co.in 
www.web-development-institute.com
In this example is created an abstract class with a property 
($name), an abstract method ( greetName() ) and a normal 
method ( setName() ). 
<?php 
// AbstractClass class 
abstract class AbstractClass { 
protected $name; 
// declare an abstract method 
abstract public function greetName($greet); 
// define a normal method 
public function setName($name) { 
$this->name = $name; // sets the value of $name property 
} 
} ?> 
www.admecindia.co.in 
www.web-development-institute.com
 Static methods and properties in php is very useful 
feature. 
 Static methods and properties in php can directly 
accessible without creating object of class. 
 Your php class will be static class if your all methods and 
properties of the class is static. 
 Static Methods and Properties in PHP will be treated as 
public if no visibility is defined. 
 Static properties of class is a property which is directly 
accessible from class with the help of ::(scope resolution 
operator). You can declare static property using static 
keyword. 
www.admecindia.co.in 
www.web-development-institute.com
 You can define a common structure for your classes using 
interfaces. 
 An Interface is like a template similar to abstract class 
with a difference where it uses only abstract methods. 
 In simple words, an interface is like a class using 
interface keyword and contains only function 
declarations(function with no body). 
 An Interface should be implemented in the class and all the 
methods or functions should be overridden in this class. 
 It is the place where we can define the function. 
When a class use that interface in that class the total 
function body part will describe. 
after that we can call that function in other class and we 
are get result. 
www.admecindia.co.in 
www.web-development-institute.com
Example of interface: 
 interface InterfaceName{ 
function fun1(); 
function fun2(a,b); 
} 
class ClassName implements InterfaceName{ 
fuction fun1(){ 
function implementation....... 
} 
fuction fun2(a,b){ 
function implementation....... 
} 
} 
www.admecindia.co.in 
www.web-development-institute.com
 For abstract class a method must be 
declared as abstract. Abstract 
methods doesn’t have any 
implementation. 
 The Abstract methods can declare 
with Access modifiers like public, 
internal, protected. When 
implementing in subclass these 
methods must be defined with the 
same (or a less restricted) visibility. 
 Abstract class can contain variables 
and concrete methods. 
 A class can Inherit only one Abstract 
class and Multiple inheritance is not 
possible for Abstract class. 
For interface all the methods by default 
are abstract methods only. So one cannot 
declare variables or concrete methods in 
interfaces. 
All methods declared in an interface must 
be public. 
Interfaces cannot contain variables and 
concrete methods except constants. 
A class can implement many interfaces 
and Multiple interface inheritance is 
possible. 
www.admecindia.co.in 
www.web-development-institute.com
PHP has available several class functions to help you through the 
OOP mine field. 
 get_declared_interfaces() 
 class_exists() 
 get_class() 
 get_declared_classes() 
 Each of these is shown here beginning with the 
get_declared_interfaces(). 
www.admecindia.co.in 
www.web-development-institute.com
get_declared_interfaces() 
following function provides an array of all the available declared 
interfaces. 
<?php 
interface fax{ 
public function dial(); 
public function send(); 
public function recieve(); 
} 
interface printer{ 
public function printBlack(); 
public function printColor(); 
public function printDraft(); 
public function kick(); 
} 
/*** our interface implementation ***/ 
class printerFax implements fax, printer{ 
public function dial(){ } 
public function send(){ } 
public function recieve(){ } 
www.admecindia.co.in 
www.web-development-institute.com
public function printBlack(){ } 
public function printColor(){ } 
public function printDraft(){ } 
public function kick(){ } 
} 
/*** create and printerfax object ***/ 
$object = new printerFax; 
/*** get the declared interfaces ***/ 
foreach(get_declared_interfaces() as $key=>$interface) 
{ 
echo $key.' =&gt; '.$interface.'<br />'; 
} 
?> 
www.admecindia.co.in 
www.web-development-institute.com
 get_class() 
 class_exists() 
 get_declared_classes 
<?php 
/*** a pretend class ***/ 
class fax{ 
public function dial(){ } 
public function send(){ } 
public function recieve(){ } 
} 
/*** another pretend class ***/ 
class printer{ 
public function printBlack(){ } 
public function printColor(){ } 
public function printDraft(){ } 
public function kick(){ } 
} 
www.admecindia.co.in 
www.web-development-institute.com
/*** create an instance of the fax class ***/ 
$foo = new fax; 
/*** create an instance of the printer class ***/ 
$bar = new printer; 
echo '$foo is from the ' get_class($foo).' class<br />'; 
echo class_exists("printer").'<br />'; 
echo 'Declared classes are:<br /> '; 
foreach(get_declared_classes() as $key=>$classname) 
{ 
echo $key.' -&gt; '.$classname.'<br />'; 
} 
?> 
www.admecindia.co.in 
www.web-development-institute.com
 Many developers writing object-oriented applications create 
one PHP source file per class definition. One of the biggest 
annoyances is having to write a long list of needed includes at 
the beginning of each script (one for each class). 
 In PHP 5, this is no longer necessary. You may define an 
__autoload() function which is automatically called in case you 
are trying to use a class/interface which hasn't been defined 
yet. By calling this function the scripting engine is given a last 
chance to load the class before PHP fails with an error. 
www.admecindia.co.in 
www.web-development-institute.com
<?php 
/*** include our class definitions ***/ 
include('classes/vehicle.class.php'); 
include('classes/motorcycle.class.php'); 
include('classes/printer.class.php'); 
include('classes/printer.class.php'); 
/*** instantiate a new vehicle class object ***/ 
$vehicle = new vehicle; 
*** instantiate a new motorcycle class object ***/ 
$bike = new motorcycle; 
*** instantiate a new printer class object ***/ 
$printer = new printer; 
*** instantiate a new fax class object ***/ 
$fax = new fax; 
?> 
www.admecindia.co.in 
www.web-development-institute.com
With __autoload() the above code can be reduce to following 
<?php 
/*** Autoload class files ***/ 
function __autoload($class){ 
require('classes/' . strtolower($class) . '.class.php'); 
} 
/*** instantiate a new vehicle class object ***/ 
$vehicle = new vehicle; 
/*** instantiate a new motorcycle class object ***/ 
$bike = new motorcycle; 
/*** instantiate a new printer class object ***/ 
$printer = new printer; 
/*** instantiate a new fax class object ***/ 
$fax = new fax; 
?> 
www.admecindia.co.in 
www.web-development-institute.com
ADMEC Multimedia Institute 
For more info you can visit 
www.admecindia.co.in and www.web-development-institute.com 
For course related enquiry, ring us at: 
9811-81-81-22, 011-3203-5055 
Created by: Parul Sabal 
Guided by: Ravi Bhadauria 
www.admecindia.co.in 
www.web-development-institute.com

More Related Content

What's hot (20)

Statements and Conditions in PHP
Statements and Conditions in PHPStatements and Conditions in PHP
Statements and Conditions in PHP
 
Php introduction
Php introductionPhp introduction
Php introduction
 
Php array
Php arrayPhp array
Php array
 
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
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
Basic i/o & file handling in java
Basic i/o & file handling in javaBasic i/o & file handling in java
Basic i/o & file handling in java
 
Php and MySQL
Php and MySQLPhp and MySQL
Php and MySQL
 
Introduction to java 8 stream api
Introduction to java 8 stream apiIntroduction to java 8 stream api
Introduction to java 8 stream api
 
Chap 4 PHP.pdf
Chap 4 PHP.pdfChap 4 PHP.pdf
Chap 4 PHP.pdf
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Class 3 - PHP Functions
Class 3 - PHP FunctionsClass 3 - PHP Functions
Class 3 - PHP Functions
 
Php
PhpPhp
Php
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
 
Django Introduction & Tutorial
Django Introduction & TutorialDjango Introduction & Tutorial
Django Introduction & Tutorial
 
Php operators
Php operatorsPhp operators
Php operators
 
Learn C# Programming - Encapsulation & Methods
Learn C# Programming - Encapsulation & MethodsLearn C# Programming - Encapsulation & Methods
Learn C# Programming - Encapsulation & Methods
 
Final keyword in java
Final keyword in javaFinal keyword in java
Final keyword in java
 
PHP FUNCTIONS
PHP FUNCTIONSPHP FUNCTIONS
PHP FUNCTIONS
 
Ado.Net Tutorial
Ado.Net TutorialAdo.Net Tutorial
Ado.Net Tutorial
 

Viewers also liked (15)

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
 
Abstract Class and Interface in PHP
Abstract Class and Interface in PHPAbstract Class and Interface in PHP
Abstract Class and Interface in PHP
 
General OOP Concepts
General OOP ConceptsGeneral OOP Concepts
General OOP Concepts
 
Oop concepts
Oop conceptsOop concepts
Oop concepts
 
Oop concepts
Oop conceptsOop concepts
Oop concepts
 
Beginning OOP in PHP
Beginning OOP in PHPBeginning OOP in PHP
Beginning OOP in PHP
 
OOP and FP - Become a Better Programmer
OOP and FP - Become a Better ProgrammerOOP and FP - Become a Better Programmer
OOP and FP - Become a Better Programmer
 
Object Oriented Programming in PHP
Object Oriented Programming in PHPObject Oriented Programming in PHP
Object Oriented Programming in PHP
 
General OOP concept [by-Digvijay]
General OOP concept [by-Digvijay]General OOP concept [by-Digvijay]
General OOP concept [by-Digvijay]
 
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
 
Oop Presentation
Oop PresentationOop Presentation
Oop Presentation
 
Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1
 
8 abstract classes and interfaces
8   abstract classes and interfaces 8   abstract classes and interfaces
8 abstract classes and interfaces
 
Login and Registration form using oop in php
Login and Registration form using oop in phpLogin and Registration form using oop in php
Login and Registration form using oop in php
 

Similar to Object oreinted php | OOPs

OOPS IN PHP.pptx
OOPS IN PHP.pptxOOPS IN PHP.pptx
OOPS IN PHP.pptxrani marri
 
Object Oriented Javascript part2
Object Oriented Javascript part2Object Oriented Javascript part2
Object Oriented Javascript part2Usman Mehmood
 
Introduction to OOP with PHP
Introduction to OOP with PHPIntroduction to OOP with PHP
Introduction to OOP with PHPMichael Peacock
 
Object-oriented programming 3.pptx
Object-oriented programming 3.pptxObject-oriented programming 3.pptx
Object-oriented programming 3.pptxAdikhan27
 
Lecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptxLecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptxShaownRoy1
 
Object oriented programming in php 5
Object oriented programming in php 5Object oriented programming in php 5
Object oriented programming in php 5Sayed Ahmed
 
Object oriented programming in php 5
Object oriented programming in php 5Object oriented programming in php 5
Object oriented programming in php 5Sayed Ahmed
 
Java OOPS Concept
Java OOPS ConceptJava OOPS Concept
Java OOPS ConceptRicha Gupta
 
Application package
Application packageApplication package
Application packageJAYAARC
 
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 CollegeDhivyaa C.R
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingAhmed Swilam
 
Basic Oops concept of PHP
Basic Oops concept of PHPBasic Oops concept of PHP
Basic Oops concept of PHPRohan Sharma
 

Similar to Object oreinted php | OOPs (20)

Only oop
Only oopOnly oop
Only oop
 
Php oop (1)
Php oop (1)Php oop (1)
Php oop (1)
 
OOPS IN PHP.pptx
OOPS IN PHP.pptxOOPS IN PHP.pptx
OOPS IN PHP.pptx
 
Object Oriented Javascript part2
Object Oriented Javascript part2Object Oriented Javascript part2
Object Oriented Javascript part2
 
Introduction to OOP with PHP
Introduction to OOP with PHPIntroduction to OOP with PHP
Introduction to OOP with PHP
 
Object-oriented programming 3.pptx
Object-oriented programming 3.pptxObject-oriented programming 3.pptx
Object-oriented programming 3.pptx
 
Lecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptxLecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptx
 
Object oriented programming in php 5
Object oriented programming in php 5Object oriented programming in php 5
Object oriented programming in php 5
 
Object oriented programming in php 5
Object oriented programming in php 5Object oriented programming in php 5
Object oriented programming in php 5
 
Java basics
Java basicsJava basics
Java basics
 
Java OOPS Concept
Java OOPS ConceptJava OOPS Concept
Java OOPS Concept
 
Application package
Application packageApplication package
Application package
 
UNIT III (8).pptx
UNIT III (8).pptxUNIT III (8).pptx
UNIT III (8).pptx
 
UNIT III (8).pptx
UNIT III (8).pptxUNIT III (8).pptx
UNIT III (8).pptx
 
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
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented Programming
 
Introduction Php
Introduction PhpIntroduction Php
Introduction Php
 
Oops in php
Oops in phpOops in php
Oops in php
 
Oop's in php
Oop's in php Oop's in php
Oop's in php
 
Basic Oops concept of PHP
Basic Oops concept of PHPBasic Oops concept of PHP
Basic Oops concept of PHP
 

More from Ravi Bhadauria

3 Important Terms of Post Production
3 Important Terms of Post Production3 Important Terms of Post Production
3 Important Terms of Post ProductionRavi Bhadauria
 
Basics of Video Editing | Types of Video Editing | Video Production Process
Basics of Video Editing | Types of Video Editing | Video Production ProcessBasics of Video Editing | Types of Video Editing | Video Production Process
Basics of Video Editing | Types of Video Editing | Video Production ProcessRavi Bhadauria
 
Basics of Media | Types of Media | Units in Media | Software in Media | Color...
Basics of Media | Types of Media | Units in Media | Software in Media | Color...Basics of Media | Types of Media | Units in Media | Software in Media | Color...
Basics of Media | Types of Media | Units in Media | Software in Media | Color...Ravi Bhadauria
 
History of Visual Communication | Guide to Visual Communication by ADMEC Mult...
History of Visual Communication | Guide to Visual Communication by ADMEC Mult...History of Visual Communication | Guide to Visual Communication by ADMEC Mult...
History of Visual Communication | Guide to Visual Communication by ADMEC Mult...Ravi Bhadauria
 
Elements and Principles of Design (Updated)
Elements and Principles of Design (Updated)Elements and Principles of Design (Updated)
Elements and Principles of Design (Updated)Ravi Bhadauria
 
Top Graphic Designing Hacks to Make You a Designing Pro Today
Top Graphic Designing Hacks to Make You a Designing Pro Today Top Graphic Designing Hacks to Make You a Designing Pro Today
Top Graphic Designing Hacks to Make You a Designing Pro Today Ravi Bhadauria
 
12 Famous Typographers to Inspire You
12 Famous Typographers to Inspire You12 Famous Typographers to Inspire You
12 Famous Typographers to Inspire YouRavi Bhadauria
 
Use of Shapes in Graphic Design | Psychology of Shapes by ADMEC (Updated)
Use of Shapes in Graphic Design | Psychology of Shapes by ADMEC (Updated)Use of Shapes in Graphic Design | Psychology of Shapes by ADMEC (Updated)
Use of Shapes in Graphic Design | Psychology of Shapes by ADMEC (Updated)Ravi Bhadauria
 
UX Design Essential Theories
UX Design Essential TheoriesUX Design Essential Theories
UX Design Essential TheoriesRavi Bhadauria
 
Workshop on resume, portfolio, interview
Workshop on resume, portfolio, interviewWorkshop on resume, portfolio, interview
Workshop on resume, portfolio, interviewRavi Bhadauria
 
Top 10 Architecture Design Colleges in India
Top 10 Architecture Design Colleges in IndiaTop 10 Architecture Design Colleges in India
Top 10 Architecture Design Colleges in IndiaRavi Bhadauria
 
User interface and user experience ui ux design basics
User interface  and user experience ui ux design basicsUser interface  and user experience ui ux design basics
User interface and user experience ui ux design basicsRavi Bhadauria
 
How to create Frost Neon Effect in Photoshop?
How to create Frost Neon Effect in Photoshop?How to create Frost Neon Effect in Photoshop?
How to create Frost Neon Effect in Photoshop?Ravi Bhadauria
 
Top 10 design colleges and institutes of india
Top 10 design colleges and institutes of indiaTop 10 design colleges and institutes of india
Top 10 design colleges and institutes of indiaRavi Bhadauria
 
Best Hollywood poster designers
Best Hollywood poster designersBest Hollywood poster designers
Best Hollywood poster designersRavi Bhadauria
 
Design Principles for All the Designers
Design Principles for All the DesignersDesign Principles for All the Designers
Design Principles for All the DesignersRavi Bhadauria
 
Content Writing Tips for SEO
Content Writing Tips for SEOContent Writing Tips for SEO
Content Writing Tips for SEORavi Bhadauria
 
6 Great Steps to Know to Create Successful Web GUI
6 Great Steps to Know to Create Successful Web GUI6 Great Steps to Know to Create Successful Web GUI
6 Great Steps to Know to Create Successful Web GUIRavi Bhadauria
 

More from Ravi Bhadauria (20)

3 Important Terms of Post Production
3 Important Terms of Post Production3 Important Terms of Post Production
3 Important Terms of Post Production
 
Basics of Video Editing | Types of Video Editing | Video Production Process
Basics of Video Editing | Types of Video Editing | Video Production ProcessBasics of Video Editing | Types of Video Editing | Video Production Process
Basics of Video Editing | Types of Video Editing | Video Production Process
 
Basics of Media | Types of Media | Units in Media | Software in Media | Color...
Basics of Media | Types of Media | Units in Media | Software in Media | Color...Basics of Media | Types of Media | Units in Media | Software in Media | Color...
Basics of Media | Types of Media | Units in Media | Software in Media | Color...
 
History of Visual Communication | Guide to Visual Communication by ADMEC Mult...
History of Visual Communication | Guide to Visual Communication by ADMEC Mult...History of Visual Communication | Guide to Visual Communication by ADMEC Mult...
History of Visual Communication | Guide to Visual Communication by ADMEC Mult...
 
Elements and Principles of Design (Updated)
Elements and Principles of Design (Updated)Elements and Principles of Design (Updated)
Elements and Principles of Design (Updated)
 
Top Graphic Designing Hacks to Make You a Designing Pro Today
Top Graphic Designing Hacks to Make You a Designing Pro Today Top Graphic Designing Hacks to Make You a Designing Pro Today
Top Graphic Designing Hacks to Make You a Designing Pro Today
 
12 Famous Typographers to Inspire You
12 Famous Typographers to Inspire You12 Famous Typographers to Inspire You
12 Famous Typographers to Inspire You
 
Sargam UI Design
Sargam UI DesignSargam UI Design
Sargam UI Design
 
Use of Shapes in Graphic Design | Psychology of Shapes by ADMEC (Updated)
Use of Shapes in Graphic Design | Psychology of Shapes by ADMEC (Updated)Use of Shapes in Graphic Design | Psychology of Shapes by ADMEC (Updated)
Use of Shapes in Graphic Design | Psychology of Shapes by ADMEC (Updated)
 
UX Design Essential Theories
UX Design Essential TheoriesUX Design Essential Theories
UX Design Essential Theories
 
Top 10 Ad Gurus
Top 10 Ad GurusTop 10 Ad Gurus
Top 10 Ad Gurus
 
Workshop on resume, portfolio, interview
Workshop on resume, portfolio, interviewWorkshop on resume, portfolio, interview
Workshop on resume, portfolio, interview
 
Top 10 Architecture Design Colleges in India
Top 10 Architecture Design Colleges in IndiaTop 10 Architecture Design Colleges in India
Top 10 Architecture Design Colleges in India
 
User interface and user experience ui ux design basics
User interface  and user experience ui ux design basicsUser interface  and user experience ui ux design basics
User interface and user experience ui ux design basics
 
How to create Frost Neon Effect in Photoshop?
How to create Frost Neon Effect in Photoshop?How to create Frost Neon Effect in Photoshop?
How to create Frost Neon Effect in Photoshop?
 
Top 10 design colleges and institutes of india
Top 10 design colleges and institutes of indiaTop 10 design colleges and institutes of india
Top 10 design colleges and institutes of india
 
Best Hollywood poster designers
Best Hollywood poster designersBest Hollywood poster designers
Best Hollywood poster designers
 
Design Principles for All the Designers
Design Principles for All the DesignersDesign Principles for All the Designers
Design Principles for All the Designers
 
Content Writing Tips for SEO
Content Writing Tips for SEOContent Writing Tips for SEO
Content Writing Tips for SEO
 
6 Great Steps to Know to Create Successful Web GUI
6 Great Steps to Know to Create Successful Web GUI6 Great Steps to Know to Create Successful Web GUI
6 Great Steps to Know to Create Successful Web GUI
 

Recently uploaded

Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
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
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........LeaCamillePacle
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxsqpmdrvczh
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
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
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 

Recently uploaded (20)

Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
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
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Romantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptxRomantic Opera MUSIC FOR GRADE NINE pptx
Romantic Opera MUSIC FOR GRADE NINE pptx
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
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
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
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
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 

Object oreinted php | OOPs

  • 1. A Presentation by ADMEC Multimedia Institute & Web Development Institute (WDI) Delhi Twitter: @admecinstitute www.admecindia.co.in www.web-development-institute.com
  • 2.  The purpose of this PHP presentation is to explain Object Oriented PHP in brief.  This PHP presentation can help a PHP programmer in understanding the terms and terminologies used in practical object oriented PHP.  Frameworks of PHP like CodeIgniter, CakePHP, Symphony, Zend etc are MVC based and knowledge of Object Oriented PHP will help in understanding all them. www.admecindia.co.in www.web-development-institute.com
  • 3.  Basics of OOP in PHP  Object & Classes in OOP  Magic Function in PHP OOP  Inheritance (Extending a class)  Visibility (public, private, protected)  Abstract Classes in PHP  Static Methods and properties in PHP  Interfaces in PHP  Explaining PHP Class Functions  Describing Autoload in PHP www.admecindia.co.in www.web-development-institute.com
  • 4.  PHP is a scripting language  Specially a Procedural Programming  Not a true OO Programming  It supports few OO features  Full OOP Support added as of PHP5
  • 5.  It is Object Oriented Programming method of coding.  Allow developer to group multiple similar tasks into classes.  The main aim of OOP is to not repeat the similar code again and again.  With OOP, it is easy to maintain the structure of application and organizing the data  OOP provide simplicity to the complex applications code. www.admecindia.co.in www.web-development-institute.com
  • 6.  Code organization and maintainability  Add clarity  Reduce complexity  Simple rules allow complex interactions  Emphasizes data over procedure  Code modularity or refactoring  Code reusability  Well-suited for databases
  • 7.  It depends  My PHP OOP rule of thumb ◦ For a simple site, OOP adds unnecessary complexity ◦ For a complex site, OOP adds necessary simplicity
  • 8. Concept of classes & objects can be explained with these two images:  A class, for example, is like a blueprint for a house. It defines the shape of the house on paper, with relationships between the different parts of the house clearly defined and planned out, even though the house doesn't exist.  An object, then, is like the actual house built according to that blueprint. The data stored in the object is like the wood, wires, and concrete that compose the house: without being assembled according to the blueprint, it's just a pile of stuff. However, when it all comes together, it becomes an organized, useful house. www.admecindia.co.in www.web-development-institute.com
  • 9. In PHP class is created using class keyword as shown in the following example class myOwnClass { //variables of the class var $variable1; var $variable2; //Function of class function mergeVariable() { return $this->variable1 . $this->variable2; } } www.admecindia.co.in www.web-development-institute.com
  • 10. There is no use of classes without objects. Object is representative of your class. If created a class then you must need to create object of the class to solve your problem using class. You can create object of your class by using new keyword. $objClass = new myClass(); Now in above code you are creating object of class myClass in variable $objClass. You can create multiple object of your same class. Every object is different from other. $objClass1 = new myClass(); $objClass2 = new myClass(); www.admecindia.co.in www.web-development-institute.com
  • 11. Magic methods in php are some predefined function by php compiler which executes on some event. Magic methods starts with prefix __, for example __call, __get, __set. List of Magic Functions in PHP __construct This magic methods is called when someone create object of your class. Usually this is used for creating constructor in php5. __destruct This magic method is called when object of your class is unset. This is just opposite of __construct. www.admecindia.co.in www.web-development-institute.com
  • 12. __get This method called when your object attempt to read property or variable of the class which is inaccessible or unavailable. __set This method called when object of your class attempts to set value of the property which is really inaccessible or unavailable in your class. __isset This magic methods trigger when isset() function is applied on any property of the class which is inaccessible or unavailable. __unset __unset is something opposite of isset method. This method triggers when unset() function called on inaccessible or unavailable property of the class. www.admecindia.co.in www.web-development-institute.com
  • 13. __call __call magic method trigger when you are attempting to call method or function of the class which is either inaccessible or unavailable. __callstatic __callstatic execture when inaccessible or unavailable method is in static context. __sleep __sleep methods trigger when you are going to serialize your class object. __wakeup __wakeup executes when you are un serializing any class object. www.admecindia.co.in www.web-development-institute.com
  • 14. There are 3 type of visibility available in PHP for controlling your property or method.  Public: Public method or variable can be accessible from anywhere. I mean from inside the class, out side the class and in child(will discuss in next chapter) class also.  Private: Method or property with private visibility can only be accessible inside the class. You can not access private method or variable from outside of your class.  Protected: Method or variable with protected visibility can only be access in the derived class. Or in other word in child class. Protected will be used in the process of inheritance. www.admecindia.co.in www.web-development-institute.com
  • 15.  The abstract classes and methods are used to create a model of minimum required methods which must be defined in normal sub-classes derived from an abstract class (with extends).  An abstract class is created with the abstract keyword.  An abstract class cannot be instantiated, can only be inherited by other sub-classes extended from it.  The abstract methods are declared with the abstract keyword, and cannot have an implementation, they simply declare the method's signature. abstract public function method Name($arguments); www.admecindia.co.in www.web-development-institute.com
  • 16. In this example is created an abstract class with a property ($name), an abstract method ( greetName() ) and a normal method ( setName() ). <?php // AbstractClass class abstract class AbstractClass { protected $name; // declare an abstract method abstract public function greetName($greet); // define a normal method public function setName($name) { $this->name = $name; // sets the value of $name property } } ?> www.admecindia.co.in www.web-development-institute.com
  • 17.  Static methods and properties in php is very useful feature.  Static methods and properties in php can directly accessible without creating object of class.  Your php class will be static class if your all methods and properties of the class is static.  Static Methods and Properties in PHP will be treated as public if no visibility is defined.  Static properties of class is a property which is directly accessible from class with the help of ::(scope resolution operator). You can declare static property using static keyword. www.admecindia.co.in www.web-development-institute.com
  • 18.  You can define a common structure for your classes using interfaces.  An Interface is like a template similar to abstract class with a difference where it uses only abstract methods.  In simple words, an interface is like a class using interface keyword and contains only function declarations(function with no body).  An Interface should be implemented in the class and all the methods or functions should be overridden in this class.  It is the place where we can define the function. When a class use that interface in that class the total function body part will describe. after that we can call that function in other class and we are get result. www.admecindia.co.in www.web-development-institute.com
  • 19. Example of interface:  interface InterfaceName{ function fun1(); function fun2(a,b); } class ClassName implements InterfaceName{ fuction fun1(){ function implementation....... } fuction fun2(a,b){ function implementation....... } } www.admecindia.co.in www.web-development-institute.com
  • 20.  For abstract class a method must be declared as abstract. Abstract methods doesn’t have any implementation.  The Abstract methods can declare with Access modifiers like public, internal, protected. When implementing in subclass these methods must be defined with the same (or a less restricted) visibility.  Abstract class can contain variables and concrete methods.  A class can Inherit only one Abstract class and Multiple inheritance is not possible for Abstract class. For interface all the methods by default are abstract methods only. So one cannot declare variables or concrete methods in interfaces. All methods declared in an interface must be public. Interfaces cannot contain variables and concrete methods except constants. A class can implement many interfaces and Multiple interface inheritance is possible. www.admecindia.co.in www.web-development-institute.com
  • 21. PHP has available several class functions to help you through the OOP mine field.  get_declared_interfaces()  class_exists()  get_class()  get_declared_classes()  Each of these is shown here beginning with the get_declared_interfaces(). www.admecindia.co.in www.web-development-institute.com
  • 22. get_declared_interfaces() following function provides an array of all the available declared interfaces. <?php interface fax{ public function dial(); public function send(); public function recieve(); } interface printer{ public function printBlack(); public function printColor(); public function printDraft(); public function kick(); } /*** our interface implementation ***/ class printerFax implements fax, printer{ public function dial(){ } public function send(){ } public function recieve(){ } www.admecindia.co.in www.web-development-institute.com
  • 23. public function printBlack(){ } public function printColor(){ } public function printDraft(){ } public function kick(){ } } /*** create and printerfax object ***/ $object = new printerFax; /*** get the declared interfaces ***/ foreach(get_declared_interfaces() as $key=>$interface) { echo $key.' =&gt; '.$interface.'<br />'; } ?> www.admecindia.co.in www.web-development-institute.com
  • 24.  get_class()  class_exists()  get_declared_classes <?php /*** a pretend class ***/ class fax{ public function dial(){ } public function send(){ } public function recieve(){ } } /*** another pretend class ***/ class printer{ public function printBlack(){ } public function printColor(){ } public function printDraft(){ } public function kick(){ } } www.admecindia.co.in www.web-development-institute.com
  • 25. /*** create an instance of the fax class ***/ $foo = new fax; /*** create an instance of the printer class ***/ $bar = new printer; echo '$foo is from the ' get_class($foo).' class<br />'; echo class_exists("printer").'<br />'; echo 'Declared classes are:<br /> '; foreach(get_declared_classes() as $key=>$classname) { echo $key.' -&gt; '.$classname.'<br />'; } ?> www.admecindia.co.in www.web-development-institute.com
  • 26.  Many developers writing object-oriented applications create one PHP source file per class definition. One of the biggest annoyances is having to write a long list of needed includes at the beginning of each script (one for each class).  In PHP 5, this is no longer necessary. You may define an __autoload() function which is automatically called in case you are trying to use a class/interface which hasn't been defined yet. By calling this function the scripting engine is given a last chance to load the class before PHP fails with an error. www.admecindia.co.in www.web-development-institute.com
  • 27. <?php /*** include our class definitions ***/ include('classes/vehicle.class.php'); include('classes/motorcycle.class.php'); include('classes/printer.class.php'); include('classes/printer.class.php'); /*** instantiate a new vehicle class object ***/ $vehicle = new vehicle; *** instantiate a new motorcycle class object ***/ $bike = new motorcycle; *** instantiate a new printer class object ***/ $printer = new printer; *** instantiate a new fax class object ***/ $fax = new fax; ?> www.admecindia.co.in www.web-development-institute.com
  • 28. With __autoload() the above code can be reduce to following <?php /*** Autoload class files ***/ function __autoload($class){ require('classes/' . strtolower($class) . '.class.php'); } /*** instantiate a new vehicle class object ***/ $vehicle = new vehicle; /*** instantiate a new motorcycle class object ***/ $bike = new motorcycle; /*** instantiate a new printer class object ***/ $printer = new printer; /*** instantiate a new fax class object ***/ $fax = new fax; ?> www.admecindia.co.in www.web-development-institute.com
  • 29. ADMEC Multimedia Institute For more info you can visit www.admecindia.co.in and www.web-development-institute.com For course related enquiry, ring us at: 9811-81-81-22, 011-3203-5055 Created by: Parul Sabal Guided by: Ravi Bhadauria www.admecindia.co.in www.web-development-institute.com