SlideShare una empresa de Scribd logo
1 de 16
Object-Oriented PHP
R. M. S. U. Gunathilake
www.eduLanka.lk
Largest Online education School in Sri Lanka
2 / 15
Object-Oriented Programming
 Object-oriented programming (OOP) refers
to the creation of reusable software objects
that can be easily incorporated into multiple
programs
 An object refers to programming code and
data that can be treated as an individual unit
or component
 Objects are often also called components
R. M. S. U. Gunathilake – www.eduLanka.lk
Object-Oriented Programming
 Data refers to information contained within
variables or other types of storage structures
 The functions associated with an object are
called methods
 The variables that are associated with an
object are called properties or attributes
 Popular object-oriented programming
languages include C++, Java, and Visual
Basic
R. M. S. U. Gunathilake – www.eduLanka.lk 3 / 15
R. M. S. U. Gunathilake – www.eduLanka.lk
Object-Oriented Programming and Classes
 The code, methods, attributes, and other
information that make up an object are
organized into classes
 An instance is an object that has been
created from an existing class
 Creating an object from an existing class is
called instantiating the object
4 / 15
Using Objects in PHP Scripts
 PHP is a Open source server side scripting
language most widely used in web
development industry
 Declare an object in PHP by using the new
operator with a class constructor
 The syntax for instantiating an object is:
$ObjectName = new ClassName();
R. M. S. U. Gunathilake – www.eduLanka.lk 5 / 15
R. M. S. U. Gunathilake – www.eduLanka.lk
Using Objects in PHP Scripts
 The identifiers for an object name:
 Must begin with a dollar sign
 Can include numbers or an underscore
 Cannot include spaces
 Are case sensitive
$Checking = new BankAccount();
 Can pass arguments to many constructor
functions
$Checking = new BankAccount(01234587, 1021, 97.58);
6 / 15
Using Objects in PHP Scripts (continued)
 After an object is instantiated, use a hyphen
and a greater-than symbol (->) to access the
methods and properties contained in the
object
 Together, these two characters are referred
to as member selection notation
 Like functions, methods can also accept
arguments
$Checking->getBalance();
$Checking->getCheckAmount($CheckNumber);
R. M. S. U. Gunathilake – www.eduLanka.lk 7 / 15
Defining Custom PHP Classes
 Data structure refers to a system for
organizing data
 The functions and variables defined in a class
are called class members
 Class variables are referred to as data
members or member variables
 Class functions are referred to as member
functions or function members
R. M. S. U. Gunathilake – www.eduLanka.lk 8 / 15
Defining Custom PHP Classes
 Classes:
 Help make complex programs easier to manage
 Hide information that users of a class do not need
to access or know about
 Make it easier to reuse code or distribute your
code to others for use in their programs
 Inherited characteristics allow you to build
new classes based on existing classes
without having to rewrite the code contained
in the existing one
R. M. S. U. Gunathilake – www.eduLanka.lk 9 / 15
R. M. S. U. Gunathilake – www.eduLanka.lk
Creating a Class Definition (continued)
 To create a class in PHP, use the class
keyword to write a class definition
 The ClassName portion of the class definition
is the name of the new class
 Class names usually begin with an uppercase
letter to distinguish them from other identifiers
 The syntax for defining a class is:
class ClassName {
data member and member function definitions
}
10 / 15
Using Access Specifiers
 Access specifiers control a client’s access
to individual data members and member
functions
 There are three levels of access specifiers in
PHP: public, private, and protected
 The public access specifier allows anyone
to call a class’s member function or to modify
a data member
R. M. S. U. Gunathilake – www.eduLanka.lk 11 / 15
Working with Member Functions
class BankAccount {
public $Balance = 958.20;
public function withdrawal($Amount) {
$this->Balance -= $Amount;
}
}
if (class_exists("BankAccount"))
$Checking = new BankAccount();
else
exit("<p>The BankAccount class is not available!</p>");
printf("<p>Your checking account balance is $%.2f.</p>",
$Checking->Balance);
$Cash = 200;
$Checking->withdrawal(200);
printf("<p>After withdrawing $%.2f, your checking account
balance is $%.2f.</p>", $Cash, $Checking->Balance);
R. M. S. U. Gunathilake – www.eduLanka.lk 12 / 15
Initializing with Constructor Functions
 The __construct() function takes
precedence over a function with the same
name as the class
 Constructor functions are commonly used in
PHP to handle database connection tasks
R. M. S. U. Gunathilake – www.eduLanka.lk 13 / 15
Initializing with Constructor Functions
 A constructor function is a special function
that is called automatically when an object
from a class is instantiated
class BankAccount {
private $AccountNumber;
private $CustomerName;
private $Balance;
function __construct() {
$this->AccountNumber = 0;
$this->Balance = 0;
$this->CustomerName = "";
}
R. M. S. U. Gunathilake – www.eduLanka.lk 14 / 15
Finally,
 OO and Classes can be used as well as PHP
 OO PHP is popular in today
 Joomla, Moodle, Mambo, Drupal, All types of
Forum software and Latest web industry have
moved into OO PHP
 Because of OO PHP, several software, MIS,
Inventory Mgt. Systems & etc.. can be
developed in secure classes
 Also desktop Apps. will move to online Apps.
R. M. S. U. Gunathilake – www.eduLanka.lk 15 / 15
THANK YOU !
R. M. S. U. Gunathilake – www.eduLanka.lk

Más contenido relacionado

Similar a OO PHP eduLanka.lk

StudentInformationSystemAndroidbased.pptx
StudentInformationSystemAndroidbased.pptxStudentInformationSystemAndroidbased.pptx
StudentInformationSystemAndroidbased.pptxSayantanMajhi2
 
Il 09 T3 William Spreitzer
Il 09 T3 William SpreitzerIl 09 T3 William Spreitzer
Il 09 T3 William Spreitzerwspreitzer
 
Krishna_chaitanya Java Developer
Krishna_chaitanya Java DeveloperKrishna_chaitanya Java Developer
Krishna_chaitanya Java DeveloperKRISHNA CHAITANYA S
 
Case Study For Data Governance Portal
Case Study For Data Governance PortalCase Study For Data Governance Portal
Case Study For Data Governance PortalMike Taylor
 
MOOC: Python & Web as Architecture
MOOC: Python & Web as ArchitectureMOOC: Python & Web as Architecture
MOOC: Python & Web as ArchitectureRizky Ariestiyansyah
 
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
 
Object Oriented PHP - PART-1
Object Oriented PHP - PART-1Object Oriented PHP - PART-1
Object Oriented PHP - PART-1Jalpesh Vasa
 
Tech bug webinar Blackboard Learn OpenDB
Tech bug webinar Blackboard Learn OpenDBTech bug webinar Blackboard Learn OpenDB
Tech bug webinar Blackboard Learn OpenDBScott Hurrey
 
OOPS IN PHP.pptx
OOPS IN PHP.pptxOOPS IN PHP.pptx
OOPS IN PHP.pptxrani marri
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingAhmed Swilam
 
Persistant Cookies and LDAP Injection
Persistant Cookies and LDAP InjectionPersistant Cookies and LDAP Injection
Persistant Cookies and LDAP InjectionMaulikLakhani
 
1 introduction
1 introduction1 introduction
1 introductionUtkarsh De
 
Building social and RESTful frameworks
Building social and RESTful frameworksBuilding social and RESTful frameworks
Building social and RESTful frameworksbrendonschwartz
 
1Intro.PPT
1Intro.PPT1Intro.PPT
1Intro.PPTMitrBhat
 

Similar a OO PHP eduLanka.lk (20)

StudentInformationSystemAndroidbased.pptx
StudentInformationSystemAndroidbased.pptxStudentInformationSystemAndroidbased.pptx
StudentInformationSystemAndroidbased.pptx
 
Il 09 T3 William Spreitzer
Il 09 T3 William SpreitzerIl 09 T3 William Spreitzer
Il 09 T3 William Spreitzer
 
Krishna_chaitanya Java Developer
Krishna_chaitanya Java DeveloperKrishna_chaitanya Java Developer
Krishna_chaitanya Java Developer
 
Case Study For Data Governance Portal
Case Study For Data Governance PortalCase Study For Data Governance Portal
Case Study For Data Governance Portal
 
An Overview of Entity Framework
An Overview of Entity FrameworkAn Overview of Entity Framework
An Overview of Entity Framework
 
PHP & mySQL Training in Bangalore at myTectra
PHP & mySQL Training in Bangalore at myTectraPHP & mySQL Training in Bangalore at myTectra
PHP & mySQL Training in Bangalore at myTectra
 
P mysql training in bangalore
P mysql training in bangaloreP mysql training in bangalore
P mysql training in bangalore
 
MOOC: Python & Web as Architecture
MOOC: Python & Web as ArchitectureMOOC: Python & Web as Architecture
MOOC: Python & Web as Architecture
 
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
 
Object Oriented PHP - PART-1
Object Oriented PHP - PART-1Object Oriented PHP - PART-1
Object Oriented PHP - PART-1
 
Tech bug webinar Blackboard Learn OpenDB
Tech bug webinar Blackboard Learn OpenDBTech bug webinar Blackboard Learn OpenDB
Tech bug webinar Blackboard Learn OpenDB
 
OOPS IN PHP.pptx
OOPS IN PHP.pptxOOPS IN PHP.pptx
OOPS IN PHP.pptx
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented Programming
 
Persistant Cookies and LDAP Injection
Persistant Cookies and LDAP InjectionPersistant Cookies and LDAP Injection
Persistant Cookies and LDAP Injection
 
Tanish Srivastava
Tanish SrivastavaTanish Srivastava
Tanish Srivastava
 
1 introduction
1 introduction1 introduction
1 introduction
 
Building social and RESTful frameworks
Building social and RESTful frameworksBuilding social and RESTful frameworks
Building social and RESTful frameworks
 
1Intro.PPT
1Intro.PPT1Intro.PPT
1Intro.PPT
 

Último

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 

Último (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 

OO PHP eduLanka.lk

  • 1. Object-Oriented PHP R. M. S. U. Gunathilake www.eduLanka.lk Largest Online education School in Sri Lanka
  • 2. 2 / 15 Object-Oriented Programming  Object-oriented programming (OOP) refers to the creation of reusable software objects that can be easily incorporated into multiple programs  An object refers to programming code and data that can be treated as an individual unit or component  Objects are often also called components R. M. S. U. Gunathilake – www.eduLanka.lk
  • 3. Object-Oriented Programming  Data refers to information contained within variables or other types of storage structures  The functions associated with an object are called methods  The variables that are associated with an object are called properties or attributes  Popular object-oriented programming languages include C++, Java, and Visual Basic R. M. S. U. Gunathilake – www.eduLanka.lk 3 / 15
  • 4. R. M. S. U. Gunathilake – www.eduLanka.lk Object-Oriented Programming and Classes  The code, methods, attributes, and other information that make up an object are organized into classes  An instance is an object that has been created from an existing class  Creating an object from an existing class is called instantiating the object 4 / 15
  • 5. Using Objects in PHP Scripts  PHP is a Open source server side scripting language most widely used in web development industry  Declare an object in PHP by using the new operator with a class constructor  The syntax for instantiating an object is: $ObjectName = new ClassName(); R. M. S. U. Gunathilake – www.eduLanka.lk 5 / 15
  • 6. R. M. S. U. Gunathilake – www.eduLanka.lk Using Objects in PHP Scripts  The identifiers for an object name:  Must begin with a dollar sign  Can include numbers or an underscore  Cannot include spaces  Are case sensitive $Checking = new BankAccount();  Can pass arguments to many constructor functions $Checking = new BankAccount(01234587, 1021, 97.58); 6 / 15
  • 7. Using Objects in PHP Scripts (continued)  After an object is instantiated, use a hyphen and a greater-than symbol (->) to access the methods and properties contained in the object  Together, these two characters are referred to as member selection notation  Like functions, methods can also accept arguments $Checking->getBalance(); $Checking->getCheckAmount($CheckNumber); R. M. S. U. Gunathilake – www.eduLanka.lk 7 / 15
  • 8. Defining Custom PHP Classes  Data structure refers to a system for organizing data  The functions and variables defined in a class are called class members  Class variables are referred to as data members or member variables  Class functions are referred to as member functions or function members R. M. S. U. Gunathilake – www.eduLanka.lk 8 / 15
  • 9. Defining Custom PHP Classes  Classes:  Help make complex programs easier to manage  Hide information that users of a class do not need to access or know about  Make it easier to reuse code or distribute your code to others for use in their programs  Inherited characteristics allow you to build new classes based on existing classes without having to rewrite the code contained in the existing one R. M. S. U. Gunathilake – www.eduLanka.lk 9 / 15
  • 10. R. M. S. U. Gunathilake – www.eduLanka.lk Creating a Class Definition (continued)  To create a class in PHP, use the class keyword to write a class definition  The ClassName portion of the class definition is the name of the new class  Class names usually begin with an uppercase letter to distinguish them from other identifiers  The syntax for defining a class is: class ClassName { data member and member function definitions } 10 / 15
  • 11. Using Access Specifiers  Access specifiers control a client’s access to individual data members and member functions  There are three levels of access specifiers in PHP: public, private, and protected  The public access specifier allows anyone to call a class’s member function or to modify a data member R. M. S. U. Gunathilake – www.eduLanka.lk 11 / 15
  • 12. Working with Member Functions class BankAccount { public $Balance = 958.20; public function withdrawal($Amount) { $this->Balance -= $Amount; } } if (class_exists("BankAccount")) $Checking = new BankAccount(); else exit("<p>The BankAccount class is not available!</p>"); printf("<p>Your checking account balance is $%.2f.</p>", $Checking->Balance); $Cash = 200; $Checking->withdrawal(200); printf("<p>After withdrawing $%.2f, your checking account balance is $%.2f.</p>", $Cash, $Checking->Balance); R. M. S. U. Gunathilake – www.eduLanka.lk 12 / 15
  • 13. Initializing with Constructor Functions  The __construct() function takes precedence over a function with the same name as the class  Constructor functions are commonly used in PHP to handle database connection tasks R. M. S. U. Gunathilake – www.eduLanka.lk 13 / 15
  • 14. Initializing with Constructor Functions  A constructor function is a special function that is called automatically when an object from a class is instantiated class BankAccount { private $AccountNumber; private $CustomerName; private $Balance; function __construct() { $this->AccountNumber = 0; $this->Balance = 0; $this->CustomerName = ""; } R. M. S. U. Gunathilake – www.eduLanka.lk 14 / 15
  • 15. Finally,  OO and Classes can be used as well as PHP  OO PHP is popular in today  Joomla, Moodle, Mambo, Drupal, All types of Forum software and Latest web industry have moved into OO PHP  Because of OO PHP, several software, MIS, Inventory Mgt. Systems & etc.. can be developed in secure classes  Also desktop Apps. will move to online Apps. R. M. S. U. Gunathilake – www.eduLanka.lk 15 / 15
  • 16. THANK YOU ! R. M. S. U. Gunathilake – www.eduLanka.lk