SlideShare a Scribd company logo
1 of 6
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Interface
• Interface is an empty class which contains only the
declaration of methods.
• So any class which implements this interface must
contain the declared functions in it.
• Interface is nothing but a strict ruling, which helps to
extend any class and strictly implement all methods
defined in interface.
• A class can use any interface by using the implements
keyword.
• In interface you can only declare methods, but you
cannot write their body.
• That means the body of all methods must remain blank.
• One of the reasons is it implies strict rules while creating
a class.
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Interface Cont…
<?
//interface.dbdriver.php
interface DBDriver
{
public function connect();
public function execute($sql);
}
?>
• Did you notice that the functions are empty in an interface? Now let's
create our MySQLDriver class, which implements this interface.
<?
//class.mysqldriver.php
include("interface.dbdriver.php");
class MySQLDriver implements DBDriver
{
}
?>
• Now if you execute the code above, it will Fatal error, since we have
not implemented all methods in child class.
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Interface Cont…
<?
include("interface.dbdriver.php");
class MySQLDriver implements DBDriver
{
public function connect()
{
//connect to database
}
public function execute($query)
{
//execute the query and output result
}
}
?>
• Let's rewrite our MySQLDriver class as follows.
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Abstract Classes
• An abstract class is almost the same as interface.
• Except that now the methods can contain body.
• An abstract class must also be "extended", not "implemented".
• If the extended classes have some methods with common
functionalities, then you can define those functions in an abstract
class.
<?
//abstract.reportgenerator.php
abstract class ReportGenerator
{
public function generateReport($resultArray)
{
//write code to process the multidimensional result array and
//generate HTML Report
}
}
?>
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Abstract Classes Cont…
• Please note that we can use the abstract class and implement an
interface.
• Similar to declaring a class as abstract, you can also declare any
method as abstract.
• When a method is declared as abstract, it means that the subclass
must override that method.
<?
include("interface.dbdriver.php");
include("abstract.reportgenerator.php");
class MySQLDriver extends ReportGenerator implements DBDriver
{
public function connect()
{
//connect to database
}
public function execute($query)
{
//execute the query and output result
}
/ / you need not declare or write the generateReport method here you need not declare or write the
generateReport method here
//again as it is extended from the abstract class directly."
}
?>
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Abstract Classes Cont…
• Please note that we can use the abstract class and implement an
interface.
• Similar to declaring a class as abstract, you can also declare any
method as abstract.
• When a method is declared as abstract, it means that the subclass
must override that method.
<?
include("interface.dbdriver.php");
include("abstract.reportgenerator.php");
class MySQLDriver extends ReportGenerator implements DBDriver
{
public function connect()
{
//connect to database
}
public function execute($query)
{
//execute the query and output result
}
/ / you need not declare or write the generateReport method here you need not declare or write the
generateReport method here
//again as it is extended from the abstract class directly."
}
?>

More Related Content

What's hot

Beginners Guide to Object Orientation in PHP
Beginners Guide to Object Orientation in PHPBeginners Guide to Object Orientation in PHP
Beginners Guide to Object Orientation in PHPRick Ogden
 
Final keyword in java
Final keyword in javaFinal keyword in java
Final keyword in javaHitesh Kumar
 
Jsp tag library
Jsp tag libraryJsp tag library
Jsp tag librarysandeep54552
 
Javascript Road Trip(es6)
Javascript Road Trip(es6)Javascript Road Trip(es6)
Javascript Road Trip(es6)Ahmed Assaf
 
Functions in sap hana
Functions in sap hanaFunctions in sap hana
Functions in sap hanakabilarasan R
 
Learn To Code: Introduction to c
Learn To Code: Introduction to cLearn To Code: Introduction to c
Learn To Code: Introduction to cSadhanaParameswaran
 
Java Chapter 04 - Writing Classes: part 2
Java Chapter 04 - Writing Classes: part 2Java Chapter 04 - Writing Classes: part 2
Java Chapter 04 - Writing Classes: part 2DanWooster1
 

What's hot (7)

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
 
Final keyword in java
Final keyword in javaFinal keyword in java
Final keyword in java
 
Jsp tag library
Jsp tag libraryJsp tag library
Jsp tag library
 
Javascript Road Trip(es6)
Javascript Road Trip(es6)Javascript Road Trip(es6)
Javascript Road Trip(es6)
 
Functions in sap hana
Functions in sap hanaFunctions in sap hana
Functions in sap hana
 
Learn To Code: Introduction to c
Learn To Code: Introduction to cLearn To Code: Introduction to c
Learn To Code: Introduction to c
 
Java Chapter 04 - Writing Classes: part 2
Java Chapter 04 - Writing Classes: part 2Java Chapter 04 - Writing Classes: part 2
Java Chapter 04 - Writing Classes: part 2
 

Viewers also liked

PHP mysql Installing my sql 5.1
PHP mysql  Installing my sql 5.1PHP mysql  Installing my sql 5.1
PHP mysql Installing my sql 5.1Mudasir Syed
 
PHP mysql Sql
PHP mysql  SqlPHP mysql  Sql
PHP mysql SqlMudasir Syed
 
Web forms and html lecture Number 2
Web forms and html lecture Number 2Web forms and html lecture Number 2
Web forms and html lecture Number 2Mudasir Syed
 
Cookies in php lecture 2
Cookies in php  lecture  2Cookies in php  lecture  2
Cookies in php lecture 2Mudasir Syed
 
Web forms and html lecture Number 5
Web forms and html lecture Number 5Web forms and html lecture Number 5
Web forms and html lecture Number 5Mudasir Syed
 
Error reporting in php
Error reporting in php Error reporting in php
Error reporting in php Mudasir Syed
 
Adminstrating Through PHPMyAdmin
Adminstrating Through PHPMyAdminAdminstrating Through PHPMyAdmin
Adminstrating Through PHPMyAdminMudasir Syed
 
Time manipulation lecture 1
Time manipulation lecture 1 Time manipulation lecture 1
Time manipulation lecture 1 Mudasir Syed
 
PHP mysql Er diagram
PHP mysql  Er diagramPHP mysql  Er diagram
PHP mysql Er diagramMudasir Syed
 
Cookies in php lecture 1
Cookies in php lecture 1Cookies in php lecture 1
Cookies in php lecture 1Mudasir Syed
 
PHP mysql Database normalizatin
PHP mysql  Database normalizatinPHP mysql  Database normalizatin
PHP mysql Database normalizatinMudasir Syed
 
Reporting using FPDF
Reporting using FPDFReporting using FPDF
Reporting using FPDFMudasir Syed
 
PHP mysql Mysql joins
PHP mysql  Mysql joinsPHP mysql  Mysql joins
PHP mysql Mysql joinsMudasir Syed
 
Time manipulation lecture 2
Time manipulation lecture 2Time manipulation lecture 2
Time manipulation lecture 2Mudasir Syed
 
Oop in php lecture 2
Oop in  php lecture 2Oop in  php lecture 2
Oop in php lecture 2Mudasir Syed
 
Form validation server side
Form validation server side Form validation server side
Form validation server side Mudasir Syed
 
Form validation with built in functions
Form validation with built in functions Form validation with built in functions
Form validation with built in functions Mudasir Syed
 

Viewers also liked (20)

Ajax
Ajax Ajax
Ajax
 
PHP mysql Installing my sql 5.1
PHP mysql  Installing my sql 5.1PHP mysql  Installing my sql 5.1
PHP mysql Installing my sql 5.1
 
PHP mysql Sql
PHP mysql  SqlPHP mysql  Sql
PHP mysql Sql
 
Web forms and html lecture Number 2
Web forms and html lecture Number 2Web forms and html lecture Number 2
Web forms and html lecture Number 2
 
Cookies in php lecture 2
Cookies in php  lecture  2Cookies in php  lecture  2
Cookies in php lecture 2
 
Web forms and html lecture Number 5
Web forms and html lecture Number 5Web forms and html lecture Number 5
Web forms and html lecture Number 5
 
Error reporting in php
Error reporting in php Error reporting in php
Error reporting in php
 
Adminstrating Through PHPMyAdmin
Adminstrating Through PHPMyAdminAdminstrating Through PHPMyAdmin
Adminstrating Through PHPMyAdmin
 
Php Mysql
Php Mysql Php Mysql
Php Mysql
 
Time manipulation lecture 1
Time manipulation lecture 1 Time manipulation lecture 1
Time manipulation lecture 1
 
PHP mysql Er diagram
PHP mysql  Er diagramPHP mysql  Er diagram
PHP mysql Er diagram
 
Cookies in php lecture 1
Cookies in php lecture 1Cookies in php lecture 1
Cookies in php lecture 1
 
PHP mysql Database normalizatin
PHP mysql  Database normalizatinPHP mysql  Database normalizatin
PHP mysql Database normalizatin
 
Reporting using FPDF
Reporting using FPDFReporting using FPDF
Reporting using FPDF
 
Sql select
Sql select Sql select
Sql select
 
PHP mysql Mysql joins
PHP mysql  Mysql joinsPHP mysql  Mysql joins
PHP mysql Mysql joins
 
Time manipulation lecture 2
Time manipulation lecture 2Time manipulation lecture 2
Time manipulation lecture 2
 
Oop in php lecture 2
Oop in  php lecture 2Oop in  php lecture 2
Oop in php lecture 2
 
Form validation server side
Form validation server side Form validation server side
Form validation server side
 
Form validation with built in functions
Form validation with built in functions Form validation with built in functions
Form validation with built in functions
 

Similar to Oop in php lecture 2

12.2 Abstract class and Interface.ppt
12.2 Abstract class and Interface.ppt12.2 Abstract class and Interface.ppt
12.2 Abstract class and Interface.pptVISHNUSHANKARSINGH3
 
J2EE vs JavaEE
J2EE vs JavaEEJ2EE vs JavaEE
J2EE vs JavaEEeanimou
 
JSP Directives
JSP DirectivesJSP Directives
JSP DirectivesShahDhruv21
 
SMI - Introduction to Java
SMI - Introduction to JavaSMI - Introduction to Java
SMI - Introduction to JavaSMIJava
 
Java interfaces
Java interfacesJava interfaces
Java interfacesSujit Kumar
 
What is Interface in Java | How to implement Multiple Inheritance Using Inter...
What is Interface in Java | How to implement Multiple Inheritance Using Inter...What is Interface in Java | How to implement Multiple Inheritance Using Inter...
What is Interface in Java | How to implement Multiple Inheritance Using Inter...Edureka!
 
Unit 2 Fundamentals of React -------.pptx
Unit 2 Fundamentals of React -------.pptxUnit 2 Fundamentals of React -------.pptx
Unit 2 Fundamentals of React -------.pptxkrishitajariwala72
 
Intro to java 8
Intro to java 8Intro to java 8
Intro to java 8John Godoi
 
Understanding And Using Reflection
Understanding And Using ReflectionUnderstanding And Using Reflection
Understanding And Using ReflectionGanesh Samarthyam
 
Zend framework: Getting to grips (ZF1)
Zend framework: Getting to grips (ZF1)Zend framework: Getting to grips (ZF1)
Zend framework: Getting to grips (ZF1)Ryan Mauger
 
Webinar: Zend framework Getting to grips (ZF1)
Webinar: Zend framework Getting to grips (ZF1)Webinar: Zend framework Getting to grips (ZF1)
Webinar: Zend framework Getting to grips (ZF1)Ryan Mauger
 
OOFeatures_revised-2.pptx
OOFeatures_revised-2.pptxOOFeatures_revised-2.pptx
OOFeatures_revised-2.pptxssuser84e52e
 
Drupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesDrupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesShabir Ahmad
 
Concurrency Programming in Java - 02 - Essentials of Java Part 1
Concurrency Programming in Java - 02 - Essentials of Java Part 1Concurrency Programming in Java - 02 - Essentials of Java Part 1
Concurrency Programming in Java - 02 - Essentials of Java Part 1Sachintha Gunasena
 
Creational Design Patterns
Creational Design PatternsCreational Design Patterns
Creational Design PatternsJamie (Taka) Wang
 
Comparison of different access controls
Comparison of different access controlsComparison of different access controls
Comparison of different access controlsRashmi Nair
 

Similar to Oop in php lecture 2 (20)

12.2 Abstract class and Interface.ppt
12.2 Abstract class and Interface.ppt12.2 Abstract class and Interface.ppt
12.2 Abstract class and Interface.ppt
 
J2EE vs JavaEE
J2EE vs JavaEEJ2EE vs JavaEE
J2EE vs JavaEE
 
JSP Directives
JSP DirectivesJSP Directives
JSP Directives
 
SMI - Introduction to Java
SMI - Introduction to JavaSMI - Introduction to Java
SMI - Introduction to Java
 
java.pptx
java.pptxjava.pptx
java.pptx
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
What is Interface in Java | How to implement Multiple Inheritance Using Inter...
What is Interface in Java | How to implement Multiple Inheritance Using Inter...What is Interface in Java | How to implement Multiple Inheritance Using Inter...
What is Interface in Java | How to implement Multiple Inheritance Using Inter...
 
Unit 2 Fundamentals of React -------.pptx
Unit 2 Fundamentals of React -------.pptxUnit 2 Fundamentals of React -------.pptx
Unit 2 Fundamentals of React -------.pptx
 
Intro to java 8
Intro to java 8Intro to java 8
Intro to java 8
 
Understanding And Using Reflection
Understanding And Using ReflectionUnderstanding And Using Reflection
Understanding And Using Reflection
 
Zend framework: Getting to grips (ZF1)
Zend framework: Getting to grips (ZF1)Zend framework: Getting to grips (ZF1)
Zend framework: Getting to grips (ZF1)
 
Webinar: Zend framework Getting to grips (ZF1)
Webinar: Zend framework Getting to grips (ZF1)Webinar: Zend framework Getting to grips (ZF1)
Webinar: Zend framework Getting to grips (ZF1)
 
Java interfaces
Java   interfacesJava   interfaces
Java interfaces
 
OOFeatures_revised-2.pptx
OOFeatures_revised-2.pptxOOFeatures_revised-2.pptx
OOFeatures_revised-2.pptx
 
Drupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesDrupal 8 - Core and API Changes
Drupal 8 - Core and API Changes
 
The smartpath information systems java
The smartpath information systems javaThe smartpath information systems java
The smartpath information systems java
 
Concurrency Programming in Java - 02 - Essentials of Java Part 1
Concurrency Programming in Java - 02 - Essentials of Java Part 1Concurrency Programming in Java - 02 - Essentials of Java Part 1
Concurrency Programming in Java - 02 - Essentials of Java Part 1
 
Creational Design Patterns
Creational Design PatternsCreational Design Patterns
Creational Design Patterns
 
Comparison of different access controls
Comparison of different access controlsComparison of different access controls
Comparison of different access controls
 
Jdbc
JdbcJdbc
Jdbc
 

More from Mudasir Syed

Filing system in PHP
Filing system in PHPFiling system in PHP
Filing system in PHPMudasir Syed
 
PHP mysql Introduction database
 PHP mysql  Introduction database PHP mysql  Introduction database
PHP mysql Introduction databaseMudasir Syed
 
PHP mysql Aggregate functions
PHP mysql Aggregate functionsPHP mysql Aggregate functions
PHP mysql Aggregate functionsMudasir Syed
 
Form validation client side
Form validation client side Form validation client side
Form validation client side Mudasir Syed
 
Javascript lecture 4
Javascript lecture  4Javascript lecture  4
Javascript lecture 4Mudasir Syed
 
Javascript lecture 3
Javascript lecture 3Javascript lecture 3
Javascript lecture 3Mudasir Syed
 
Javascript 2
Javascript 2Javascript 2
Javascript 2Mudasir Syed
 
Java script lecture 1
Java script lecture 1Java script lecture 1
Java script lecture 1Mudasir Syed
 
Dom in javascript
Dom in javascriptDom in javascript
Dom in javascriptMudasir Syed
 
Functions in php
Functions in phpFunctions in php
Functions in phpMudasir Syed
 

More from Mudasir Syed (12)

Filing system in PHP
Filing system in PHPFiling system in PHP
Filing system in PHP
 
PHP mysql Introduction database
 PHP mysql  Introduction database PHP mysql  Introduction database
PHP mysql Introduction database
 
PHP mysql Aggregate functions
PHP mysql Aggregate functionsPHP mysql Aggregate functions
PHP mysql Aggregate functions
 
Form validation client side
Form validation client side Form validation client side
Form validation client side
 
Javascript lecture 4
Javascript lecture  4Javascript lecture  4
Javascript lecture 4
 
Javascript lecture 3
Javascript lecture 3Javascript lecture 3
Javascript lecture 3
 
Javascript 2
Javascript 2Javascript 2
Javascript 2
 
Java script lecture 1
Java script lecture 1Java script lecture 1
Java script lecture 1
 
Dom in javascript
Dom in javascriptDom in javascript
Dom in javascript
 
Functions in php
Functions in phpFunctions in php
Functions in php
 
PHP array 2
PHP array 2PHP array 2
PHP array 2
 
PHP array 1
PHP array 1PHP array 1
PHP array 1
 

Recently uploaded

How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)Dr. Mazin Mohamed alkathiri
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
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
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 

Recently uploaded (20)

Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
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
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 

Oop in php lecture 2

  • 1. © Copyright 2012 Hidaya Trust (Pakistan) â—Ź A Non-Profit Organization â—Ź www.hidayatrust.org / www,histpk.org Interface • Interface is an empty class which contains only the declaration of methods. • So any class which implements this interface must contain the declared functions in it. • Interface is nothing but a strict ruling, which helps to extend any class and strictly implement all methods defined in interface. • A class can use any interface by using the implements keyword. • In interface you can only declare methods, but you cannot write their body. • That means the body of all methods must remain blank. • One of the reasons is it implies strict rules while creating a class.
  • 2. © Copyright 2012 Hidaya Trust (Pakistan) â—Ź A Non-Profit Organization â—Ź www.hidayatrust.org / www,histpk.org Interface Cont… <? //interface.dbdriver.php interface DBDriver { public function connect(); public function execute($sql); } ?> • Did you notice that the functions are empty in an interface? Now let's create our MySQLDriver class, which implements this interface. <? //class.mysqldriver.php include("interface.dbdriver.php"); class MySQLDriver implements DBDriver { } ?> • Now if you execute the code above, it will Fatal error, since we have not implemented all methods in child class.
  • 3. © Copyright 2012 Hidaya Trust (Pakistan) â—Ź A Non-Profit Organization â—Ź www.hidayatrust.org / www,histpk.org Interface Cont… <? include("interface.dbdriver.php"); class MySQLDriver implements DBDriver { public function connect() { //connect to database } public function execute($query) { //execute the query and output result } } ?> • Let's rewrite our MySQLDriver class as follows.
  • 4. © Copyright 2012 Hidaya Trust (Pakistan) â—Ź A Non-Profit Organization â—Ź www.hidayatrust.org / www,histpk.org Abstract Classes • An abstract class is almost the same as interface. • Except that now the methods can contain body. • An abstract class must also be "extended", not "implemented". • If the extended classes have some methods with common functionalities, then you can define those functions in an abstract class. <? //abstract.reportgenerator.php abstract class ReportGenerator { public function generateReport($resultArray) { //write code to process the multidimensional result array and //generate HTML Report } } ?>
  • 5. © Copyright 2012 Hidaya Trust (Pakistan) â—Ź A Non-Profit Organization â—Ź www.hidayatrust.org / www,histpk.org Abstract Classes Cont… • Please note that we can use the abstract class and implement an interface. • Similar to declaring a class as abstract, you can also declare any method as abstract. • When a method is declared as abstract, it means that the subclass must override that method. <? include("interface.dbdriver.php"); include("abstract.reportgenerator.php"); class MySQLDriver extends ReportGenerator implements DBDriver { public function connect() { //connect to database } public function execute($query) { //execute the query and output result } / / you need not declare or write the generateReport method here you need not declare or write the generateReport method here //again as it is extended from the abstract class directly." } ?>
  • 6. © Copyright 2012 Hidaya Trust (Pakistan) â—Ź A Non-Profit Organization â—Ź www.hidayatrust.org / www,histpk.org Abstract Classes Cont… • Please note that we can use the abstract class and implement an interface. • Similar to declaring a class as abstract, you can also declare any method as abstract. • When a method is declared as abstract, it means that the subclass must override that method. <? include("interface.dbdriver.php"); include("abstract.reportgenerator.php"); class MySQLDriver extends ReportGenerator implements DBDriver { public function connect() { //connect to database } public function execute($query) { //execute the query and output result } / / you need not declare or write the generateReport method here you need not declare or write the generateReport method here //again as it is extended from the abstract class directly." } ?>