SlideShare ist ein Scribd-Unternehmen logo
1 von 35
PHP Classes
and
Object Orientation
Revision HIstory
#

Version

Date

Rationale for
change

1

1.0

26-Feb-2008

Initial Version

2

Change Description
Revision HIstory
Document Name

Training Material

Document Code

QMS-TEM-OT 08

Version

1.0

Date

26-Feb-2008

Created By

Ms. Padmavathy

Reviewed BY

SPG

Approved By

Mr. Vijay
Agenda
•
•
•
•
•
•
•

Introduction
Function
Class Definition
Class Usage
Constructor
Inheritance
PHP4 vs PHP5
Reminder… a function
• Reusable piece of code.
• Has its own ‘local scope’.
function my_func($arg1,$arg2) {
<< function statements >>
}
Conceptually, what does a
function represent?
…give the function something (arguments), it does
something with them, and then returns a result…

Action or
Method
What is a class?

Conceptually, a class represents an
object, with associated methods
and variables
Class Definition
<?php
class dog {
public $name;
public function bark() {
echo ‘Woof!’;
}
}
?>

An example class
definition for a dog.
The dog object has a
single attribute, the
name, and can
perform the action of
barking.
Class Definition
<?php
Define the name of the class.
class dog { class dog {
public $name;
public function bark() {
echo ‘Woof!’;
}
}
?>
Class Definition
<?php
class dog { public $name;
public $name;
public function bark() {
echo ‘Woof!’; Define an object attribute
(variable), the dog’s name.
}
}
?>
Class Definition
<?php
Define an object
action (function), the
class dog {
dog’s bark.
public $name;
public function bark() {
echo ‘Woof!’;
}
public function bark() {
echo ‘Woof!’;
}
}
?>
Class Defintion
Similar to defining a function..
The definition does not do anything by
itself. It is a blueprint, or description, of an
object. To do something, you need to use
the class…
Class Usage
<?php
require(‘dog.class.php’);
$puppy = new dog();
$puppy->name = ‘Rover’;
echo “{$puppy->name} says ”;
$puppy->bark();
?>
Class Usage
<?php require(‘dog.class.php’);
require(‘dog.class.php’);
$puppy = new dog();
$puppy->name = ‘Rover’;
Include the class definition
echo “{$puppy->name} says ”;
$puppy->bark();
?>
Class Usage
<?php
require(‘dog.class.php’);
$puppy = new dog();
$puppy = new dog();
$puppy->name = ‘Rover’;
echo “{$puppy->name} Create a new”; of the
says instance
class.
$puppy->bark();
?>
Class Usage
<?php
require(‘dog.class.php’);
$puppy = new dog();
$puppy->name = ‘Rover’;
$puppy->name = ‘Rover’;
echo “{$puppy->name} says ”;
Set the name variable of this
$puppy->bark();
instance to ‘Rover’.
?>
Class Usage
<?php
require(‘dog.class.php’); Use the name variable
of this instance in an
echo statement..
$puppy = new dog();
$puppy->name = ‘Rover’;
echo “{$puppy->name} says ”;
echo “{$puppy->name} says ”;
$puppy->bark();
?>
Class Usage
<?php
require(‘dog.class.php’);
Use the dog object
$puppy = new dog();
bark method.
$puppy->name = ‘Rover’;
echo “{$puppy->name} says ”;
$puppy->bark();
$puppy->bark();
?>
One dollar and one only…
$puppy->name = ‘Rover’;
The most common mistake is to use more
than one dollar sign when accessing
variables. The following means something
entirely different..

$puppy->$name = ‘Rover’;
Using attributes within the
class..
• If you need to use the class variables
within any class actions, use the special
variable $this in the definition:
class dog {
public $name;
public function bark() {
echo $this->name.‘ says Woof!’;
}
}
Constructor methods
• A constructor method is a function that is
automatically executed when the class is
first instantiated.
• Create a constructor by including a
function within the class definition with the
__construct name.
• Remember.. if the constructor requires
arguments, they must be passed when it
is instantiated!
Constructor Example
<?php
class dog {
public $name;
public function __construct($nametext) {
$this->name = $nametext;
}
public function bark() {
echo ‘Woof!’;
}
}
?>
Constructor Example
<?php
…
$puppy = new dog(‘Rover’);
…
?>
Constructor arguments are passed during the
instantiation of the object.
Class Scope
• Like functions, each instantiated object
has its own local scope.
e.g. if 2 different dog objects are
instantiated, $puppy1 and $puppy2, the
two dog names $puppy1->name and
$puppy2->name are entirely
independent..
Inheritance
• The real power of using classes is the
property of inheritance – creating a
hierarchy of interlinked classes.
dog
parent
children
poodle

alsatian
Inheritance
• The child classes ‘inherit’ all the methods
and variables of the parent class, and can
add extra ones of their own.
e.g. the child classes poodle inherits the
variable ‘name’ and method ‘bark’ from the
dog class, and can add extra ones…
Inheritance example
The American Kennel Club (AKC) recognizes three sizes of poodle - Standard,
Miniature, and Toy…

class poodle extends dog {
public $type;
public function set_type($height) {
if ($height<10) {
$this->type = ‘Toy’;
} elseif ($height>15) {
$this->type = ‘Standard’;
} else {
$this->type = ‘Miniature’;
}
}
}
Inheritance example
The American Kennel Club (AKC) recognizes three sizes of poodle - Standard,
Miniature, and Toy…

class poodle extends dog { class poodle extends dog {
public $type;
public function set_type($height) {
if ($height<10) {
Note the use of the extends keyword to
$this->type = ‘Toy’;
indicate that the poodle class is a child o
the dog class…
} elseif ($height>15) {
$this->type = ‘Standard’;
} else {
$this->type = ‘Miniature’;
}
}
}
Inheritance example

…
$puppy = new poodle(‘Oscar’);
$puppy->set_type(12); // 12 inches high!
echo “Poodle is called {$puppy->name}, ”;
echo “of type {$puppy->type}, saying “;
echo $puppy->bark();
…
…a poodle will always ‘Yip!’
• It is possible to over-ride a parent method with a new
method if it is given the same name in the child class..
class poodle extends dog {
…
public function bark() {
echo ‘Yip!’;
}
…
}
Child Constructors?
• If the child class possesses a constructor
function, it is executed and any parent
constructor is ignored.
• If the child class does not have a constructor,
the parent’s constructor is executed.
• If the child and parent does not have a
constructor, the grandparent constructor is
attempted…
• … etc.
Deleting objects
• So far our objects have not been
destroyed till the end of our scripts..
• Like variables, it is possible to explicitly
destroy an object using the unset()
function.
There is a lot more…
• We have really only touched the edge of
object orientated programming…
• But I don’t want to confuse you too much!
PHP4 vs. PHP5
• OOP purists will tell you that the object
support in PHP4 is sketchy. They are
right, in that a lot of features are missing.
• PHP5 OOP system has had a big
redesign and is much better.
…but it is worth it to produce OOP
code in either PHP4 or PHP5…
Oops implemetation material

Weitere ähnliche Inhalte

Was ist angesagt?

Inheritance And Traits
Inheritance And TraitsInheritance And Traits
Inheritance And Traits
Piyush Mishra
 
0php 5-online-cheat-sheet-v1-3
0php 5-online-cheat-sheet-v1-30php 5-online-cheat-sheet-v1-3
0php 5-online-cheat-sheet-v1-3
Fafah Ranaivo
 
Computación evolutiva en Perl
Computación evolutiva en PerlComputación evolutiva en Perl
Computación evolutiva en Perl
Juan J. Merelo
 
Introducing Modern Perl
Introducing Modern PerlIntroducing Modern Perl
Introducing Modern Perl
Dave Cross
 
Scripting3
Scripting3Scripting3
Scripting3
Nao Dara
 

Was ist angesagt? (20)

Python programming : Inheritance and polymorphism
Python programming : Inheritance and polymorphismPython programming : Inheritance and polymorphism
Python programming : Inheritance and polymorphism
 
Marc’s (bio)perl course
Marc’s (bio)perl courseMarc’s (bio)perl course
Marc’s (bio)perl course
 
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAPYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
 
PHP OOP
PHP OOPPHP OOP
PHP OOP
 
DBIx::Class beginners
DBIx::Class beginnersDBIx::Class beginners
DBIx::Class beginners
 
Python unit 3 m.sc cs
Python unit 3 m.sc csPython unit 3 m.sc cs
Python unit 3 m.sc cs
 
Python Lecture 13
Python Lecture 13Python Lecture 13
Python Lecture 13
 
PowerShell 101
PowerShell 101PowerShell 101
PowerShell 101
 
Working with text, Regular expressions
Working with text, Regular expressionsWorking with text, Regular expressions
Working with text, Regular expressions
 
LPW: Beginners Perl
LPW: Beginners PerlLPW: Beginners Perl
LPW: Beginners Perl
 
Inheritance And Traits
Inheritance And TraitsInheritance And Traits
Inheritance And Traits
 
Pa1 session 3_slides
Pa1 session 3_slidesPa1 session 3_slides
Pa1 session 3_slides
 
DBIx::Class introduction - 2010
DBIx::Class introduction - 2010DBIx::Class introduction - 2010
DBIx::Class introduction - 2010
 
0php 5-online-cheat-sheet-v1-3
0php 5-online-cheat-sheet-v1-30php 5-online-cheat-sheet-v1-3
0php 5-online-cheat-sheet-v1-3
 
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
 
Hashes
HashesHashes
Hashes
 
Computación evolutiva en Perl
Computación evolutiva en PerlComputación evolutiva en Perl
Computación evolutiva en Perl
 
Introducing Modern Perl
Introducing Modern PerlIntroducing Modern Perl
Introducing Modern Perl
 
Perl
PerlPerl
Perl
 
Scripting3
Scripting3Scripting3
Scripting3
 

Ähnlich wie Oops implemetation material

PHP-05-Objects.ppt
PHP-05-Objects.pptPHP-05-Objects.ppt
PHP-05-Objects.ppt
rani marri
 
SPL: The Missing Link in Development
SPL: The Missing Link in DevelopmentSPL: The Missing Link in Development
SPL: The Missing Link in Development
jsmith92
 

Ähnlich wie Oops implemetation material (20)

SQL Devlopment for 10 ppt
SQL Devlopment for 10 pptSQL Devlopment for 10 ppt
SQL Devlopment for 10 ppt
 
06-classes.ppt (copy).pptx
06-classes.ppt (copy).pptx06-classes.ppt (copy).pptx
06-classes.ppt (copy).pptx
 
Ch8(oop)
Ch8(oop)Ch8(oop)
Ch8(oop)
 
Object-Oriented Programming with PHP (part 1)
Object-Oriented Programming with PHP (part 1)Object-Oriented Programming with PHP (part 1)
Object-Oriented Programming with PHP (part 1)
 
PHP-05-Objects.ppt
PHP-05-Objects.pptPHP-05-Objects.ppt
PHP-05-Objects.ppt
 
SPL: The Missing Link in Development
SPL: The Missing Link in DevelopmentSPL: The Missing Link in Development
SPL: The Missing Link in Development
 
Lecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptxLecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptx
 
FFW Gabrovo PMG - PHP OOP Part 3
FFW Gabrovo PMG - PHP OOP Part 3FFW Gabrovo PMG - PHP OOP Part 3
FFW Gabrovo PMG - PHP OOP Part 3
 
Objects, Testing, and Responsibility
Objects, Testing, and ResponsibilityObjects, Testing, and Responsibility
Objects, Testing, and Responsibility
 
14 Defining classes
14 Defining classes14 Defining classes
14 Defining classes
 
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
 
Lecture 17 - PHP-Object-Orientation.pptx
Lecture 17 - PHP-Object-Orientation.pptxLecture 17 - PHP-Object-Orientation.pptx
Lecture 17 - PHP-Object-Orientation.pptx
 
OOP
OOPOOP
OOP
 
Demystifying Object-Oriented Programming #phpbnl18
Demystifying Object-Oriented Programming #phpbnl18Demystifying Object-Oriented Programming #phpbnl18
Demystifying Object-Oriented Programming #phpbnl18
 
OOP in PHP.pptx
OOP in PHP.pptxOOP in PHP.pptx
OOP in PHP.pptx
 
Object Oriented Programming in PHP
Object Oriented Programming in PHPObject Oriented Programming in PHP
Object Oriented Programming in PHP
 
OOPs Concept
OOPs ConceptOOPs Concept
OOPs Concept
 
Demystifying Object-Oriented Programming - Lone Star PHP
Demystifying Object-Oriented Programming - Lone Star PHPDemystifying Object-Oriented Programming - Lone Star PHP
Demystifying Object-Oriented Programming - Lone Star PHP
 

Mehr von Deepak Solanki

Ulttrasonic metal welding
Ulttrasonic metal weldingUlttrasonic metal welding
Ulttrasonic metal welding
Deepak Solanki
 
Electromagnetic suspension-system
Electromagnetic suspension-systemElectromagnetic suspension-system
Electromagnetic suspension-system
Deepak Solanki
 
Object-Oriented Programming (OOPS) in C++
Object-Oriented Programming (OOPS) in C++Object-Oriented Programming (OOPS) in C++
Object-Oriented Programming (OOPS) in C++
Deepak Solanki
 
Automobile fluid coupling and torque converter
Automobile fluid coupling and torque converterAutomobile fluid coupling and torque converter
Automobile fluid coupling and torque converter
Deepak Solanki
 

Mehr von Deepak Solanki (20)

Ulttrasonic metal welding
Ulttrasonic metal weldingUlttrasonic metal welding
Ulttrasonic metal welding
 
Steering Operated Vehicle Illumination(Head Lighting) System
Steering Operated Vehicle Illumination(Head Lighting) SystemSteering Operated Vehicle Illumination(Head Lighting) System
Steering Operated Vehicle Illumination(Head Lighting) System
 
Modified Fiat Bogie
Modified Fiat BogieModified Fiat Bogie
Modified Fiat Bogie
 
Loco workshop
Loco workshopLoco workshop
Loco workshop
 
Indian Railway : An Introduction
Indian Railway : An IntroductionIndian Railway : An Introduction
Indian Railway : An Introduction
 
ICF Bogie
ICF BogieICF Bogie
ICF Bogie
 
Casnub Bogies
Casnub BogiesCasnub Bogies
Casnub Bogies
 
Fiat bogie
Fiat bogieFiat bogie
Fiat bogie
 
Bogie under frame
Bogie under frameBogie under frame
Bogie under frame
 
Bogie and suspension e book
Bogie and suspension e bookBogie and suspension e book
Bogie and suspension e book
 
bio diesel
 bio diesel bio diesel
bio diesel
 
HMT training report
HMT training reportHMT training report
HMT training report
 
Kota Super Thermal Power Station Training report
Kota Super Thermal Power Station Training reportKota Super Thermal Power Station Training report
Kota Super Thermal Power Station Training report
 
Electromagnetic suspension-system
Electromagnetic suspension-systemElectromagnetic suspension-system
Electromagnetic suspension-system
 
Cimmco wagon mfg and suspension system
Cimmco wagon mfg and suspension systemCimmco wagon mfg and suspension system
Cimmco wagon mfg and suspension system
 
Suspension system
Suspension systemSuspension system
Suspension system
 
Bhel Pnuematic Braking System
Bhel Pnuematic Braking SystemBhel Pnuematic Braking System
Bhel Pnuematic Braking System
 
Object-Oriented Programming (OOPS) in C++
Object-Oriented Programming (OOPS) in C++Object-Oriented Programming (OOPS) in C++
Object-Oriented Programming (OOPS) in C++
 
Duarts
DuartsDuarts
Duarts
 
Automobile fluid coupling and torque converter
Automobile fluid coupling and torque converterAutomobile fluid coupling and torque converter
Automobile fluid coupling and torque converter
 

Kürzlich hochgeladen

💞Call Girls In Sonipat 08168329307 Sonipat Kundli GTK Bypass EsCoRt Service
💞Call Girls In Sonipat 08168329307 Sonipat Kundli GTK Bypass EsCoRt Service💞Call Girls In Sonipat 08168329307 Sonipat Kundli GTK Bypass EsCoRt Service
💞Call Girls In Sonipat 08168329307 Sonipat Kundli GTK Bypass EsCoRt Service
Apsara Of India
 
Zirakpur Call Girls👧 Book Now📱8146719683 📞👉Mohali Call Girl Service No Advanc...
Zirakpur Call Girls👧 Book Now📱8146719683 📞👉Mohali Call Girl Service No Advanc...Zirakpur Call Girls👧 Book Now📱8146719683 📞👉Mohali Call Girl Service No Advanc...
Zirakpur Call Girls👧 Book Now📱8146719683 📞👉Mohali Call Girl Service No Advanc...
rajveermohali2022
 
👉Amritsar Escorts📞Book Now📞👉 8725944379 👉Amritsar Escort Service No Advance C...
👉Amritsar Escorts📞Book Now📞👉 8725944379 👉Amritsar Escort Service No Advance C...👉Amritsar Escorts📞Book Now📞👉 8725944379 👉Amritsar Escort Service No Advance C...
👉Amritsar Escorts📞Book Now📞👉 8725944379 👉Amritsar Escort Service No Advance C...
Sheetaleventcompany
 
New Call Girls In Panipat 08168329307 Shamli Israna Escorts Service
New Call Girls In Panipat 08168329307 Shamli Israna Escorts ServiceNew Call Girls In Panipat 08168329307 Shamli Israna Escorts Service
New Call Girls In Panipat 08168329307 Shamli Israna Escorts Service
Apsara Of India
 
💞ROYAL💞 UDAIPUR ESCORTS Call 09602870969 CaLL GiRLS in UdAiPuR EsCoRt SeRvIcE💞
💞ROYAL💞 UDAIPUR ESCORTS Call 09602870969 CaLL GiRLS in UdAiPuR EsCoRt SeRvIcE💞💞ROYAL💞 UDAIPUR ESCORTS Call 09602870969 CaLL GiRLS in UdAiPuR EsCoRt SeRvIcE💞
💞ROYAL💞 UDAIPUR ESCORTS Call 09602870969 CaLL GiRLS in UdAiPuR EsCoRt SeRvIcE💞
Apsara Of India
 
💞5✨ Hotel Karnal Call Girls 08168329307 Noor Mahal Karnal Escort Service
💞5✨ Hotel Karnal Call Girls 08168329307 Noor Mahal Karnal Escort Service💞5✨ Hotel Karnal Call Girls 08168329307 Noor Mahal Karnal Escort Service
💞5✨ Hotel Karnal Call Girls 08168329307 Noor Mahal Karnal Escort Service
Apsara Of India
 
💗📲09602870969💕-Royal Escorts in Udaipur Call Girls Service Udaipole-Fateh Sag...
💗📲09602870969💕-Royal Escorts in Udaipur Call Girls Service Udaipole-Fateh Sag...💗📲09602870969💕-Royal Escorts in Udaipur Call Girls Service Udaipole-Fateh Sag...
💗📲09602870969💕-Royal Escorts in Udaipur Call Girls Service Udaipole-Fateh Sag...
Apsara Of India
 
Call Now ☎ 8264348440 !! Call Girls in Govindpuri Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Govindpuri Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Govindpuri Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Govindpuri Escort Service Delhi N.C.R.
soniya singh
 
💞SEXY💞 UDAIPUR ESCORTS 09602870969 CaLL GiRLS in UdAiPuR EsCoRt SeRvIcE💞
💞SEXY💞 UDAIPUR ESCORTS 09602870969 CaLL GiRLS in UdAiPuR EsCoRt SeRvIcE💞💞SEXY💞 UDAIPUR ESCORTS 09602870969 CaLL GiRLS in UdAiPuR EsCoRt SeRvIcE💞
💞SEXY💞 UDAIPUR ESCORTS 09602870969 CaLL GiRLS in UdAiPuR EsCoRt SeRvIcE💞
Apsara Of India
 

Kürzlich hochgeladen (20)

💞Call Girls In Sonipat 08168329307 Sonipat Kundli GTK Bypass EsCoRt Service
💞Call Girls In Sonipat 08168329307 Sonipat Kundli GTK Bypass EsCoRt Service💞Call Girls In Sonipat 08168329307 Sonipat Kundli GTK Bypass EsCoRt Service
💞Call Girls In Sonipat 08168329307 Sonipat Kundli GTK Bypass EsCoRt Service
 
Pooja : 9892124323, Dharavi Call Girls. 7000 Cash Payment Free Home Delivery
Pooja : 9892124323, Dharavi Call Girls. 7000 Cash Payment Free Home DeliveryPooja : 9892124323, Dharavi Call Girls. 7000 Cash Payment Free Home Delivery
Pooja : 9892124323, Dharavi Call Girls. 7000 Cash Payment Free Home Delivery
 
Dubai Call Girls Phone O525547819 Take+ Call Girls Dubai=
Dubai Call Girls Phone O525547819 Take+ Call Girls Dubai=Dubai Call Girls Phone O525547819 Take+ Call Girls Dubai=
Dubai Call Girls Phone O525547819 Take+ Call Girls Dubai=
 
Zirakpur Call Girls👧 Book Now📱8146719683 📞👉Mohali Call Girl Service No Advanc...
Zirakpur Call Girls👧 Book Now📱8146719683 📞👉Mohali Call Girl Service No Advanc...Zirakpur Call Girls👧 Book Now📱8146719683 📞👉Mohali Call Girl Service No Advanc...
Zirakpur Call Girls👧 Book Now📱8146719683 📞👉Mohali Call Girl Service No Advanc...
 
👉Amritsar Escorts📞Book Now📞👉 8725944379 👉Amritsar Escort Service No Advance C...
👉Amritsar Escorts📞Book Now📞👉 8725944379 👉Amritsar Escort Service No Advance C...👉Amritsar Escorts📞Book Now📞👉 8725944379 👉Amritsar Escort Service No Advance C...
👉Amritsar Escorts📞Book Now📞👉 8725944379 👉Amritsar Escort Service No Advance C...
 
The Clean Living Project Episode 17 - Blue Zones
The Clean Living Project Episode 17 - Blue ZonesThe Clean Living Project Episode 17 - Blue Zones
The Clean Living Project Episode 17 - Blue Zones
 
Call girls in Vashi Services : 9167673311 Free Delivery 24x7 at Your Doorstep
Call girls in Vashi Services :  9167673311 Free Delivery 24x7 at Your DoorstepCall girls in Vashi Services :  9167673311 Free Delivery 24x7 at Your Doorstep
Call girls in Vashi Services : 9167673311 Free Delivery 24x7 at Your Doorstep
 
"Maximizing your savings:The power of financial planning".pptx
"Maximizing your savings:The power of financial planning".pptx"Maximizing your savings:The power of financial planning".pptx
"Maximizing your savings:The power of financial planning".pptx
 
New Call Girls In Panipat 08168329307 Shamli Israna Escorts Service
New Call Girls In Panipat 08168329307 Shamli Israna Escorts ServiceNew Call Girls In Panipat 08168329307 Shamli Israna Escorts Service
New Call Girls In Panipat 08168329307 Shamli Israna Escorts Service
 
Call Girls in Bangalore Lavya 💋9136956627 Bangalore Call Girls
Call Girls in Bangalore Lavya 💋9136956627 Bangalore Call GirlsCall Girls in Bangalore Lavya 💋9136956627 Bangalore Call Girls
Call Girls in Bangalore Lavya 💋9136956627 Bangalore Call Girls
 
💞ROYAL💞 UDAIPUR ESCORTS Call 09602870969 CaLL GiRLS in UdAiPuR EsCoRt SeRvIcE💞
💞ROYAL💞 UDAIPUR ESCORTS Call 09602870969 CaLL GiRLS in UdAiPuR EsCoRt SeRvIcE💞💞ROYAL💞 UDAIPUR ESCORTS Call 09602870969 CaLL GiRLS in UdAiPuR EsCoRt SeRvIcE💞
💞ROYAL💞 UDAIPUR ESCORTS Call 09602870969 CaLL GiRLS in UdAiPuR EsCoRt SeRvIcE💞
 
💞5✨ Hotel Karnal Call Girls 08168329307 Noor Mahal Karnal Escort Service
💞5✨ Hotel Karnal Call Girls 08168329307 Noor Mahal Karnal Escort Service💞5✨ Hotel Karnal Call Girls 08168329307 Noor Mahal Karnal Escort Service
💞5✨ Hotel Karnal Call Girls 08168329307 Noor Mahal Karnal Escort Service
 
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
 
💗📲09602870969💕-Royal Escorts in Udaipur Call Girls Service Udaipole-Fateh Sag...
💗📲09602870969💕-Royal Escorts in Udaipur Call Girls Service Udaipole-Fateh Sag...💗📲09602870969💕-Royal Escorts in Udaipur Call Girls Service Udaipole-Fateh Sag...
💗📲09602870969💕-Royal Escorts in Udaipur Call Girls Service Udaipole-Fateh Sag...
 
Call Now ☎ 8264348440 !! Call Girls in Govindpuri Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Govindpuri Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Govindpuri Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Govindpuri Escort Service Delhi N.C.R.
 
Hire 💕 8617697112 Pulwama Call Girls Service Call Girls Agency
Hire 💕 8617697112 Pulwama Call Girls Service Call Girls AgencyHire 💕 8617697112 Pulwama Call Girls Service Call Girls Agency
Hire 💕 8617697112 Pulwama Call Girls Service Call Girls Agency
 
WhatsApp 📞 8448380779 ✅Call Girls In Bhangel Sector 102 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Bhangel Sector 102 ( Noida)WhatsApp 📞 8448380779 ✅Call Girls In Bhangel Sector 102 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Bhangel Sector 102 ( Noida)
 
💞SEXY💞 UDAIPUR ESCORTS 09602870969 CaLL GiRLS in UdAiPuR EsCoRt SeRvIcE💞
💞SEXY💞 UDAIPUR ESCORTS 09602870969 CaLL GiRLS in UdAiPuR EsCoRt SeRvIcE💞💞SEXY💞 UDAIPUR ESCORTS 09602870969 CaLL GiRLS in UdAiPuR EsCoRt SeRvIcE💞
💞SEXY💞 UDAIPUR ESCORTS 09602870969 CaLL GiRLS in UdAiPuR EsCoRt SeRvIcE💞
 
Night 7k to 12k Chennai Call Girls 👉👉 8617697112⭐⭐ 100% Genuine Escort Servic...
Night 7k to 12k Chennai Call Girls 👉👉 8617697112⭐⭐ 100% Genuine Escort Servic...Night 7k to 12k Chennai Call Girls 👉👉 8617697112⭐⭐ 100% Genuine Escort Servic...
Night 7k to 12k Chennai Call Girls 👉👉 8617697112⭐⭐ 100% Genuine Escort Servic...
 
👉Chandigarh Call Girls 📞Book Now📞👉 9878799926 👉Zirakpur Call Girl Service No ...
👉Chandigarh Call Girls 📞Book Now📞👉 9878799926 👉Zirakpur Call Girl Service No ...👉Chandigarh Call Girls 📞Book Now📞👉 9878799926 👉Zirakpur Call Girl Service No ...
👉Chandigarh Call Girls 📞Book Now📞👉 9878799926 👉Zirakpur Call Girl Service No ...
 

Oops implemetation material

  • 3. Revision HIstory Document Name Training Material Document Code QMS-TEM-OT 08 Version 1.0 Date 26-Feb-2008 Created By Ms. Padmavathy Reviewed BY SPG Approved By Mr. Vijay
  • 5. Reminder… a function • Reusable piece of code. • Has its own ‘local scope’. function my_func($arg1,$arg2) { << function statements >> }
  • 6. Conceptually, what does a function represent? …give the function something (arguments), it does something with them, and then returns a result… Action or Method
  • 7. What is a class? Conceptually, a class represents an object, with associated methods and variables
  • 8. Class Definition <?php class dog { public $name; public function bark() { echo ‘Woof!’; } } ?> An example class definition for a dog. The dog object has a single attribute, the name, and can perform the action of barking.
  • 9. Class Definition <?php Define the name of the class. class dog { class dog { public $name; public function bark() { echo ‘Woof!’; } } ?>
  • 10. Class Definition <?php class dog { public $name; public $name; public function bark() { echo ‘Woof!’; Define an object attribute (variable), the dog’s name. } } ?>
  • 11. Class Definition <?php Define an object action (function), the class dog { dog’s bark. public $name; public function bark() { echo ‘Woof!’; } public function bark() { echo ‘Woof!’; } } ?>
  • 12. Class Defintion Similar to defining a function.. The definition does not do anything by itself. It is a blueprint, or description, of an object. To do something, you need to use the class…
  • 13. Class Usage <?php require(‘dog.class.php’); $puppy = new dog(); $puppy->name = ‘Rover’; echo “{$puppy->name} says ”; $puppy->bark(); ?>
  • 14. Class Usage <?php require(‘dog.class.php’); require(‘dog.class.php’); $puppy = new dog(); $puppy->name = ‘Rover’; Include the class definition echo “{$puppy->name} says ”; $puppy->bark(); ?>
  • 15. Class Usage <?php require(‘dog.class.php’); $puppy = new dog(); $puppy = new dog(); $puppy->name = ‘Rover’; echo “{$puppy->name} Create a new”; of the says instance class. $puppy->bark(); ?>
  • 16. Class Usage <?php require(‘dog.class.php’); $puppy = new dog(); $puppy->name = ‘Rover’; $puppy->name = ‘Rover’; echo “{$puppy->name} says ”; Set the name variable of this $puppy->bark(); instance to ‘Rover’. ?>
  • 17. Class Usage <?php require(‘dog.class.php’); Use the name variable of this instance in an echo statement.. $puppy = new dog(); $puppy->name = ‘Rover’; echo “{$puppy->name} says ”; echo “{$puppy->name} says ”; $puppy->bark(); ?>
  • 18. Class Usage <?php require(‘dog.class.php’); Use the dog object $puppy = new dog(); bark method. $puppy->name = ‘Rover’; echo “{$puppy->name} says ”; $puppy->bark(); $puppy->bark(); ?>
  • 19. One dollar and one only… $puppy->name = ‘Rover’; The most common mistake is to use more than one dollar sign when accessing variables. The following means something entirely different.. $puppy->$name = ‘Rover’;
  • 20. Using attributes within the class.. • If you need to use the class variables within any class actions, use the special variable $this in the definition: class dog { public $name; public function bark() { echo $this->name.‘ says Woof!’; } }
  • 21. Constructor methods • A constructor method is a function that is automatically executed when the class is first instantiated. • Create a constructor by including a function within the class definition with the __construct name. • Remember.. if the constructor requires arguments, they must be passed when it is instantiated!
  • 22. Constructor Example <?php class dog { public $name; public function __construct($nametext) { $this->name = $nametext; } public function bark() { echo ‘Woof!’; } } ?>
  • 23. Constructor Example <?php … $puppy = new dog(‘Rover’); … ?> Constructor arguments are passed during the instantiation of the object.
  • 24. Class Scope • Like functions, each instantiated object has its own local scope. e.g. if 2 different dog objects are instantiated, $puppy1 and $puppy2, the two dog names $puppy1->name and $puppy2->name are entirely independent..
  • 25. Inheritance • The real power of using classes is the property of inheritance – creating a hierarchy of interlinked classes. dog parent children poodle alsatian
  • 26. Inheritance • The child classes ‘inherit’ all the methods and variables of the parent class, and can add extra ones of their own. e.g. the child classes poodle inherits the variable ‘name’ and method ‘bark’ from the dog class, and can add extra ones…
  • 27. Inheritance example The American Kennel Club (AKC) recognizes three sizes of poodle - Standard, Miniature, and Toy… class poodle extends dog { public $type; public function set_type($height) { if ($height<10) { $this->type = ‘Toy’; } elseif ($height>15) { $this->type = ‘Standard’; } else { $this->type = ‘Miniature’; } } }
  • 28. Inheritance example The American Kennel Club (AKC) recognizes three sizes of poodle - Standard, Miniature, and Toy… class poodle extends dog { class poodle extends dog { public $type; public function set_type($height) { if ($height<10) { Note the use of the extends keyword to $this->type = ‘Toy’; indicate that the poodle class is a child o the dog class… } elseif ($height>15) { $this->type = ‘Standard’; } else { $this->type = ‘Miniature’; } } }
  • 29. Inheritance example … $puppy = new poodle(‘Oscar’); $puppy->set_type(12); // 12 inches high! echo “Poodle is called {$puppy->name}, ”; echo “of type {$puppy->type}, saying “; echo $puppy->bark(); …
  • 30. …a poodle will always ‘Yip!’ • It is possible to over-ride a parent method with a new method if it is given the same name in the child class.. class poodle extends dog { … public function bark() { echo ‘Yip!’; } … }
  • 31. Child Constructors? • If the child class possesses a constructor function, it is executed and any parent constructor is ignored. • If the child class does not have a constructor, the parent’s constructor is executed. • If the child and parent does not have a constructor, the grandparent constructor is attempted… • … etc.
  • 32. Deleting objects • So far our objects have not been destroyed till the end of our scripts.. • Like variables, it is possible to explicitly destroy an object using the unset() function.
  • 33. There is a lot more… • We have really only touched the edge of object orientated programming… • But I don’t want to confuse you too much!
  • 34. PHP4 vs. PHP5 • OOP purists will tell you that the object support in PHP4 is sketchy. They are right, in that a lot of features are missing. • PHP5 OOP system has had a big redesign and is much better. …but it is worth it to produce OOP code in either PHP4 or PHP5…