SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Similaire à 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
 

Similaire à 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
 

Dernier

GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 

Dernier (20)

GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

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