SlideShare una empresa de Scribd logo
1 de 38
PHP Classes  and  Object Orientation
Reminder… a function ,[object Object],[object Object],[object Object],[object Object],[object Object]
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 ? ,[object Object]
Class Definition ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],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 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],class  dog { Define the  name  of the class.
Class Definition ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],public  $name; Define an object attribute (variable), the dog’s name.
Class Definition ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],public function  bark() { echo   ‘Woof!’ ; } Define an object action (function), the dog’s bark.
Class Definition ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],} End the class definition
Class Defintion ,[object Object],[object Object]
Class Usage ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Class Usage ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],require ( ‘dog.class.php’ ); Include the class definition
Class Usage ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],$puppy =  new  dog(); Create a new  instance  of the class.
Class Usage ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],$puppy->name =  ‘Rover’ ; Set the name variable  of this instance  to ‘Rover’.
Class Usage ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],echo  “ {$puppy->name}  says ” ; Use the name variable of this instance in an echo statement..
Class Usage ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],$puppy->bark(); Use the dog object bark method.
Class Usage ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[example file: classes1.php]
One dollar and one only… ,[object Object],[object Object],[object Object]
Using attributes within the class.. ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Constructor methods ,[object Object],[object Object],[object Object]
Constructor Example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Constructor function
Constructor Example ,[object Object],[object Object],[object Object],[object Object],[object Object],Constructor arguments are passed during the instantiation of the object.
Class Scope ,[object Object],[object Object]
Inheritance ,[object Object],dog poodle alsatian parent children
Inheritance ,[object Object],[object Object]
Inheritance example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Inheritance example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],class  poodle  extends  dog { Note the use of the  extends  keyword to indicate that the poodle class is a child of the dog class…
Inheritance example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
…a poodle will always ‘Yip!’ ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Child Constructors? ,[object Object],[object Object],[object Object],[object Object]
Objects within Objects ,[object Object],[object Object],… $puppy =  new  dog; $puppy->name =  “Rover" ; $poppy->tag =  new  dogtag; $poppy->tag->words =  “blah” ; …
Deleting objects ,[object Object],[object Object]
A copy, or not a copy.. ,[object Object],[object Object]
Why Object Orientate? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Why Object Orientate? ,[object Object],[object Object],[object Object]
Why Object Orientate? ,[object Object],[object Object],[object Object]
There is a lot more… ,[object Object],[object Object],[object Object]
PHP4 vs. PHP5 ,[object Object],[object Object],[object Object],[object Object]

Más contenido relacionado

La actualidad más candente

Html 5-tables-forms-frames (1)
Html 5-tables-forms-frames (1)Html 5-tables-forms-frames (1)
Html 5-tables-forms-frames (1)
club23
 
Php Using Arrays
Php Using ArraysPhp Using Arrays
Php Using Arrays
mussawir20
 

La actualidad más candente (20)

Php basics
Php basicsPhp basics
Php basics
 
Css3
Css3Css3
Css3
 
Class 5 - PHP Strings
Class 5 - PHP StringsClass 5 - PHP Strings
Class 5 - PHP Strings
 
Html 5-tables-forms-frames (1)
Html 5-tables-forms-frames (1)Html 5-tables-forms-frames (1)
Html 5-tables-forms-frames (1)
 
File Uploading in PHP
File Uploading in PHPFile Uploading in PHP
File Uploading in PHP
 
Java script
Java scriptJava script
Java script
 
HTML5 Form Validation
HTML5 Form ValidationHTML5 Form Validation
HTML5 Form Validation
 
Php with MYSQL Database
Php with MYSQL DatabasePhp with MYSQL Database
Php with MYSQL Database
 
Loops PHP 04
Loops PHP 04Loops PHP 04
Loops PHP 04
 
Css ppt
Css pptCss ppt
Css ppt
 
4.2 PHP Function
4.2 PHP Function4.2 PHP Function
4.2 PHP Function
 
Php Using Arrays
Php Using ArraysPhp Using Arrays
Php Using Arrays
 
Chapter 07 php forms handling
Chapter 07   php forms handlingChapter 07   php forms handling
Chapter 07 php forms handling
 
Operators php
Operators phpOperators php
Operators php
 
Php operators
Php operatorsPhp operators
Php operators
 
PHP - Introduction to PHP Forms
PHP - Introduction to PHP FormsPHP - Introduction to PHP Forms
PHP - Introduction to PHP Forms
 
01 Php Introduction
01 Php Introduction01 Php Introduction
01 Php Introduction
 
Html ppt
Html pptHtml ppt
Html ppt
 
Php array
Php arrayPhp array
Php array
 
html-table
html-tablehtml-table
html-table
 

Destacado

Oop in-php
Oop in-phpOop in-php
Oop in-php
Rajesh S
 

Destacado (20)

Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented Programming
 
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
 
radar
radarradar
radar
 
Oop in-php
Oop in-phpOop in-php
Oop in-php
 
Modul 3 Cara Membuat View Pada CodeIgniter
Modul 3 Cara Membuat View Pada CodeIgniterModul 3 Cara Membuat View Pada CodeIgniter
Modul 3 Cara Membuat View Pada CodeIgniter
 
Modular PHP Development using CodeIgniter Bonfire
Modular PHP Development using CodeIgniter BonfireModular PHP Development using CodeIgniter Bonfire
Modular PHP Development using CodeIgniter Bonfire
 
Functions in php
Functions in phpFunctions in php
Functions in php
 
Guide
GuideGuide
Guide
 
My SQl
My SQlMy SQl
My SQl
 
sql
sqlsql
sql
 
IP Addressing
IP AddressingIP Addressing
IP Addressing
 
Saftey
SafteySaftey
Saftey
 
Mysql
MysqlMysql
Mysql
 
1. review jurnal effect dwi hastho
1. review jurnal effect dwi hastho1. review jurnal effect dwi hastho
1. review jurnal effect dwi hastho
 
I/O Management
I/O ManagementI/O Management
I/O Management
 
Shell Script
Shell ScriptShell Script
Shell Script
 
Operating systems
Operating systemsOperating systems
Operating systems
 
Network Security
Network SecurityNetwork Security
Network Security
 
The Dining Philosophers problem in Bangla
The Dining Philosophers problem in BanglaThe Dining Philosophers problem in Bangla
The Dining Philosophers problem in Bangla
 
MSAT
MSATMSAT
MSAT
 

Similar a Class and Objects in PHP

Similar a Class and Objects in PHP (20)

PHP Classes and OOPS Concept
PHP Classes and OOPS ConceptPHP Classes and OOPS Concept
PHP Classes and OOPS Concept
 
Oops implemetation material
Oops implemetation materialOops implemetation material
Oops implemetation material
 
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
 
Php Oop
Php OopPhp Oop
Php Oop
 
Ch8(oop)
Ch8(oop)Ch8(oop)
Ch8(oop)
 
OOP
OOPOOP
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)
 
Object Oriented Programming in PHP
Object Oriented Programming  in PHPObject Oriented Programming  in PHP
Object Oriented Programming in PHP
 
Lecture 17 - PHP-Object-Orientation.pptx
Lecture 17 - PHP-Object-Orientation.pptxLecture 17 - PHP-Object-Orientation.pptx
Lecture 17 - PHP-Object-Orientation.pptx
 
OOP in PHP.pptx
OOP in PHP.pptxOOP in PHP.pptx
OOP in PHP.pptx
 
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
 
Intro to The PHP SPL
Intro to The PHP SPLIntro to The PHP SPL
Intro to The PHP SPL
 
encapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingencapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloading
 
Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5Go OO! - Real-life Design Patterns in PHP 5
Go OO! - Real-life Design Patterns in PHP 5
 
Oops concept in php
Oops concept in phpOops concept in php
Oops concept in php
 
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
 

Más de Ramasubbu .P (20)

Press
PressPress
Press
 
Milling 2
Milling 2Milling 2
Milling 2
 
MIlling 1
MIlling 1MIlling 1
MIlling 1
 
Drillings
DrillingsDrillings
Drillings
 
Holding
HoldingHolding
Holding
 
Harvesting
HarvestingHarvesting
Harvesting
 
Plough
PloughPlough
Plough
 
Tractor PTO
Tractor PTOTractor PTO
Tractor PTO
 
Tractor Components
Tractor ComponentsTractor Components
Tractor Components
 
GPS
GPSGPS
GPS
 
RTOS
RTOSRTOS
RTOS
 
Virus
VirusVirus
Virus
 
Hacker
HackerHacker
Hacker
 
Denail of Service
Denail of ServiceDenail of Service
Denail of Service
 
RAID CONCEPT
RAID CONCEPTRAID CONCEPT
RAID CONCEPT
 
Timer
TimerTimer
Timer
 
Sequential Logic Circuit
Sequential Logic CircuitSequential Logic Circuit
Sequential Logic Circuit
 
PL C
PL CPL C
PL C
 
P L C
P L CP L C
P L C
 
Ladder
LadderLadder
Ladder
 

Último

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
SanaAli374401
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 

Último (20)

Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 

Class and Objects in PHP

  • 1. PHP Classes and Object Orientation
  • 2.
  • 3. Conceptually, what does a function represent? … give the function something (arguments), it does something with them, and then returns a result… Action or Method
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.