SlideShare a Scribd company logo
6
Most read
7
Most read
9
Most read
PHP -  Introduction to  Object Oriented Programming with PHP
Introduction to Object
Oriented Programming
with PHP
Object Oriented ConceptObject Oriented Concept
ļ‚” Classes, which are the "blueprints" for an object and are the
actual code that defines the properties and methods.
ļ‚” Objects, which are running instances of a class and contain
all the internal data and state information needed for your
application to function.
ļ‚” Encapsulation, which is the capability of an object to protect
access to its internal data
ļ‚” Inheritance, which is the ability to define a class of one kind
as being a sub-type of a different kind of class (much the
same way a square is a kind of rectangle).
Creating ClassCreating Class
• Let's start with a simple example. Save the following
in a file called class.lat.php:
<?php
class Demo
{
}
?>
Adding MethodAdding Method
• The Demo class isn't particularly useful if it isn't able
to do anything, so let's look at how you can create
a method.
<?php
class Demo
{
function SayHello($name)
{
echo ā€œHello $name !ā€;
}
}
?>
Adding PropertiesAdding Properties
• Adding a property to your class is as easy as adding
a method.
<?php
class Demo
{
public $name;
function SayHello()
{
echo ā€œHello $this->$name !ā€;
}
}
?>
Object InstantiationObject Instantiation
• You can instantiate an object of type Demo like
this:
<?php
require_once('class.lat.php');
$objDemo = new Demo();
$objDemo->name = ā€œBayuā€;
$objDemo->SayHallo();
?>
Protecting Access toProtecting Access to
Member VariablesMember Variables (1)(1)ļ‚” There are three different levels of visibility that a member variable or method
can have :
ļ‚§ Public
ā–Ŗ members are accessible to any and all code
ļ‚§ Private
ā–Ŗ members are only accessible to the class itself
ļ‚§ Protected
ā–Ŗ members are available to the class itself, and to classes that inherit
from it
Public is the default visibility level for any member variables or functions
that do not explicitly set one, but it is good practice to always explicitly state
the visibility of all the members of the class.
Public is the default visibility level for any member variables or functions
that do not explicitly set one, but it is good practice to always explicitly state
the visibility of all the members of the class.
Protecting Access toProtecting Access to
Member VariablesMember Variables (2)(2)
• Try to change access level of property named
ā€œnameā€ to private of previous code.
• What the possible solution of this problem?
• Make the getter and setter function...
Always use get and set functions for your properties. Changes to business logic
and data validation requirements in the future will be much easier to
implement.
Always use get and set functions for your properties. Changes to business logic
and data validation requirements in the future will be much easier to
implement.
Class ConstantsClass Constants
ļ‚” It is possible to define constant values on a per-
class basis remaining the same and
unchangeable.
ļ‚” Constants differ from normal variables in that you
don't use the $ symbol to declare or use them
ļ‚” The value must be a constant expression, not (for
example) a variable, a property, a result of a
mathematical operation, or a function call
Class Constants (cont.)Class Constants (cont.)
<?php
classĀ MyClass
{
Ā Ā Ā Ā constĀ constantĀ =Ā 'constantĀ value';
Ā Ā Ā Ā functionĀ showConstant()Ā {
Ā Ā Ā Ā Ā Ā Ā Ā echoĀ Ā self::constantĀ .Ā "n";
Ā Ā Ā Ā }
}
echoĀ MyClass::constantĀ .Ā "n";
?>
<?php
classĀ MyClass
{
Ā Ā Ā Ā constĀ constantĀ =Ā 'constantĀ value';
Ā Ā Ā Ā functionĀ showConstant()Ā {
Ā Ā Ā Ā Ā Ā Ā Ā echoĀ Ā self::constantĀ .Ā "n";
Ā Ā Ā Ā }
}
echoĀ MyClass::constantĀ .Ā "n";
?>
Static KeywordStatic Keyword
• Declaring class properties or methods as static
makes them accessible without needing an
instantiation of the class.
• A property declared as static can not be accessed
with an instantiated class object
PHP -  Introduction to  Object Oriented Programming with PHP
ContructorContructor
• Constructor is the method that will be implemented when object has
been initiated
• Commonly, constructor is used to initialize the object
• Use function __construct to create constructor in PHP
<?php
class Demo
{
function __construct
{
}
}
?>
DestructorDestructor
• Destructor, is method that will be run when object is
ended
<?php
class Demo
{
function __destruct
{
}
}
?>
InheritanceInheritance
• There are many benefits of inheritance with PHP, the
most common is simplifying and reducing instances of
redundant code.
Inheritance (2)Inheritance (2)
class hewan
{
protected $jml_kaki;
protected $warna_kulit;
function __construct()
{
}
function berpindah()
{
echo "Saya berpindah";
}
function makan()
{
echo "Saya makan";
}
}
class hewan
{
protected $jml_kaki;
protected $warna_kulit;
function __construct()
{
}
function berpindah()
{
echo "Saya berpindah";
}
function makan()
{
echo "Saya makan";
}
}
Inherintace (3)Inherintace (3)
TugasTugas
Tugas (cont.)Tugas (cont.)
ļ‚” Class product :
ļ‚§ name
ļ‚§ price
ļ‚§ discount
ļ‚” Class CDMusic :
ļ‚§ artist
ļ‚§ Genre
ļ‚” Class CDRack
ļ‚§ capacity
ļ‚§ model
Tugas (cont.)Tugas (cont.)
ļ‚” CDMusic
ļ‚§ Menuruni name, price dan discount dari Product
ļ‚§ Price = price + 10%
ļ‚§ Ada penambahan 5% pada discount
ļ‚” CDRack
ļ‚§ Menuruni name, price dan discount dari Product
ļ‚§ Price = price + 15%
ļ‚§ Tidak ada penambahan discount
ļ‚” Buatlah code dalam PHP, serta simulasi untuk kasus
tersebut!
ThankThank You !!!You !!!
For More Information click below link:
Follow Us on:
http://vibranttechnologies.co.in/php-classes-in-
mumbai.html

More Related Content

PPT
PHP variables
Siddique Ibrahim
Ā 
PPTX
php
ajeetjhajharia
Ā 
PPTX
PHP slides
Farzad Wadia
Ā 
PDF
Php tutorial(w3schools)
Arjun Shanka
Ā 
PDF
Php Tutorials for Beginners
Vineet Kumar Saini
Ā 
PPT
Class and Objects in PHP
Ramasubbu .P
Ā 
PDF
Php array
Nikul Shah
Ā 
PDF
Php introduction
krishnapriya Tadepalli
Ā 
PHP variables
Siddique Ibrahim
Ā 
PHP slides
Farzad Wadia
Ā 
Php tutorial(w3schools)
Arjun Shanka
Ā 
Php Tutorials for Beginners
Vineet Kumar Saini
Ā 
Class and Objects in PHP
Ramasubbu .P
Ā 
Php array
Nikul Shah
Ā 
Php introduction
krishnapriya Tadepalli
Ā 

What's hot (20)

PPTX
Super keyword in java
Hitesh Kumar
Ā 
PPTX
C# classes objects
Dr.Neeraj Kumar Pandey
Ā 
ODP
Datatype in JavaScript
Rajat Saxena
Ā 
PPTX
Inheritance in java
Tech_MX
Ā 
PPT
Oops concepts in php
CPD INDIA
Ā 
PPTX
PHP FUNCTIONS
Zeeshan Ahmed
Ā 
PDF
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
Ā 
PPTX
Interface in java
PhD Research Scholar
Ā 
PPT
Network programming in Java
Tushar B Kute
Ā 
PDF
Java I/o streams
Hamid Ghorbani
Ā 
PPTX
Chapter 07 inheritance
Praveen M Jigajinni
Ā 
PPTX
Multithreading in java
Monika Mishra
Ā 
PPTX
Java Server Pages
Kasun Madusanke
Ā 
PPTX
Python OOPs
Binay Kumar Ray
Ā 
PPT
C#.NET
gurchet
Ā 
PPTX
Regular expressions in Python
Sujith Kumar
Ā 
PDF
Object oriented approach in python programming
Srinivas Narasegouda
Ā 
PPT
C# basics
Dinesh kumar
Ā 
PPT
Jsp ppt
Vikas Jagtap
Ā 
PPTX
ASP.NET Web API
habib_786
Ā 
Super keyword in java
Hitesh Kumar
Ā 
C# classes objects
Dr.Neeraj Kumar Pandey
Ā 
Datatype in JavaScript
Rajat Saxena
Ā 
Inheritance in java
Tech_MX
Ā 
Oops concepts in php
CPD INDIA
Ā 
PHP FUNCTIONS
Zeeshan Ahmed
Ā 
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
Ā 
Interface in java
PhD Research Scholar
Ā 
Network programming in Java
Tushar B Kute
Ā 
Java I/o streams
Hamid Ghorbani
Ā 
Chapter 07 inheritance
Praveen M Jigajinni
Ā 
Multithreading in java
Monika Mishra
Ā 
Java Server Pages
Kasun Madusanke
Ā 
Python OOPs
Binay Kumar Ray
Ā 
C#.NET
gurchet
Ā 
Regular expressions in Python
Sujith Kumar
Ā 
Object oriented approach in python programming
Srinivas Narasegouda
Ā 
C# basics
Dinesh kumar
Ā 
Jsp ppt
Vikas Jagtap
Ā 
ASP.NET Web API
habib_786
Ā 
Ad

Viewers also liked (14)

PDF
Object Oriented Programming in PHP
Lorna Mitchell
Ā 
PPT
Oops in PHP
Mindfire Solutions
Ā 
PPT
Object Oriented Programming Concepts
thinkphp
Ā 
PDF
OOP in PHP
Alena Holligan
Ā 
PDF
A Gentle Introduction To Object Oriented Php
Michael Girouard
Ā 
DOC
Java Servlets & JSP
Manjunatha RK
Ā 
PPTX
C vs c++
Gaurav Badhan
Ā 
PPT
APACHE TOMCAT
Rachid NID SAID
Ā 
PPT
JSP
vikram singh
Ā 
PDF
Tomcat and apache httpd training
Franck SIMON
Ā 
PPT
Java Tutorial
Vijay A Raj
Ā 
PPT
Php Presentation
Manish Bothra
Ā 
PPT
Asp.net.
Naveen Sihag
Ā 
Object Oriented Programming in PHP
Lorna Mitchell
Ā 
Oops in PHP
Mindfire Solutions
Ā 
Object Oriented Programming Concepts
thinkphp
Ā 
OOP in PHP
Alena Holligan
Ā 
A Gentle Introduction To Object Oriented Php
Michael Girouard
Ā 
Java Servlets & JSP
Manjunatha RK
Ā 
C vs c++
Gaurav Badhan
Ā 
APACHE TOMCAT
Rachid NID SAID
Ā 
Tomcat and apache httpd training
Franck SIMON
Ā 
Java Tutorial
Vijay A Raj
Ā 
Php Presentation
Manish Bothra
Ā 
Asp.net.
Naveen Sihag
Ā 
Ad

Similar to PHP - Introduction to Object Oriented Programming with PHP (20)

PPTX
Only oop
anitarooge
Ā 
PPTX
Lecture-10_PHP-OOP.pptx
ShaownRoy1
Ā 
ZIP
Object Oriented PHP5
Jason Austin
Ā 
PPT
Advanced php
hamfu
Ā 
PPTX
c91632a4-2e92-4edf-b750-358da15ed1b1.pptx
ajayparmeshwarmahaja
Ā 
PPTX
Ch8(oop)
Chhom Karath
Ā 
PPT
UNIT-IV WT web technology for 1st year cs
javed75
Ā 
PPT
Synapseindia object oriented programming in php
Synapseindiappsdevelopment
Ā 
PPTX
OOP in PHP.pptx
switipatel4
Ā 
PDF
Object Oriented Programming in PHP
wahidullah mudaser
Ā 
PPTX
Php oop (1)
Sudip Simkhada
Ā 
PPTX
Object oriented programming in php
Aashiq Kuchey
Ā 
PPT
Class 7 - PHP Object Oriented Programming
Ahmed Swilam
Ā 
DOCX
Oops concept in php
selvabalaji k
Ā 
PPTX
Chap4 oop class (php) part 1
monikadeshmane
Ā 
PPTX
UNIT III (8).pptx
DrDhivyaaCRAssistant
Ā 
PPTX
UNIT III (8).pptx
DrDhivyaaCRAssistant
Ā 
PPTX
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Dhivyaa C.R
Ā 
PDF
Object Oriented PHP - PART-1
Jalpesh Vasa
Ā 
PDF
Demystifying Object-Oriented Programming #phpbnl18
Alena Holligan
Ā 
Only oop
anitarooge
Ā 
Lecture-10_PHP-OOP.pptx
ShaownRoy1
Ā 
Object Oriented PHP5
Jason Austin
Ā 
Advanced php
hamfu
Ā 
c91632a4-2e92-4edf-b750-358da15ed1b1.pptx
ajayparmeshwarmahaja
Ā 
Ch8(oop)
Chhom Karath
Ā 
UNIT-IV WT web technology for 1st year cs
javed75
Ā 
Synapseindia object oriented programming in php
Synapseindiappsdevelopment
Ā 
OOP in PHP.pptx
switipatel4
Ā 
Object Oriented Programming in PHP
wahidullah mudaser
Ā 
Php oop (1)
Sudip Simkhada
Ā 
Object oriented programming in php
Aashiq Kuchey
Ā 
Class 7 - PHP Object Oriented Programming
Ahmed Swilam
Ā 
Oops concept in php
selvabalaji k
Ā 
Chap4 oop class (php) part 1
monikadeshmane
Ā 
UNIT III (8).pptx
DrDhivyaaCRAssistant
Ā 
UNIT III (8).pptx
DrDhivyaaCRAssistant
Ā 
Object Oriented PHP by Dr.C.R.Dhivyaa Kongu Engineering College
Dhivyaa C.R
Ā 
Object Oriented PHP - PART-1
Jalpesh Vasa
Ā 
Demystifying Object-Oriented Programming #phpbnl18
Alena Holligan
Ā 

More from Vibrant Technologies & Computers (20)

PPT
Buisness analyst business analysis overview ppt 5
Vibrant Technologies & Computers
Ā 
PPT
SQL Introduction to displaying data from multiple tables
Vibrant Technologies & Computers
Ā 
PPT
SQL- Introduction to MySQL
Vibrant Technologies & Computers
Ā 
PPT
SQL- Introduction to SQL database
Vibrant Technologies & Computers
Ā 
PPT
ITIL - introduction to ITIL
Vibrant Technologies & Computers
Ā 
PPT
Salesforce - Introduction to Security & Access
Vibrant Technologies & Computers
Ā 
PPT
Data ware housing- Introduction to olap .
Vibrant Technologies & Computers
Ā 
PPT
Data ware housing - Introduction to data ware housing process.
Vibrant Technologies & Computers
Ā 
PPT
Data ware housing- Introduction to data ware housing
Vibrant Technologies & Computers
Ā 
PPT
Salesforce - classification of cloud computing
Vibrant Technologies & Computers
Ā 
PPT
Salesforce - cloud computing fundamental
Vibrant Technologies & Computers
Ā 
PPT
SQL- Introduction to PL/SQL
Vibrant Technologies & Computers
Ā 
PPT
SQL- Introduction to advanced sql concepts
Vibrant Technologies & Computers
Ā 
PPT
SQL Inteoduction to SQL manipulating of data
Vibrant Technologies & Computers
Ā 
PPT
SQL- Introduction to SQL Set Operations
Vibrant Technologies & Computers
Ā 
PPT
Sas - Introduction to designing the data mart
Vibrant Technologies & Computers
Ā 
PPT
Sas - Introduction to working under change management
Vibrant Technologies & Computers
Ā 
PPT
SAS - overview of SAS
Vibrant Technologies & Computers
Ā 
PPT
Teradata - Architecture of Teradata
Vibrant Technologies & Computers
Ā 
PPT
Teradata - Restoring Data
Vibrant Technologies & Computers
Ā 
Buisness analyst business analysis overview ppt 5
Vibrant Technologies & Computers
Ā 
SQL Introduction to displaying data from multiple tables
Vibrant Technologies & Computers
Ā 
SQL- Introduction to MySQL
Vibrant Technologies & Computers
Ā 
SQL- Introduction to SQL database
Vibrant Technologies & Computers
Ā 
ITIL - introduction to ITIL
Vibrant Technologies & Computers
Ā 
Salesforce - Introduction to Security & Access
Vibrant Technologies & Computers
Ā 
Data ware housing- Introduction to olap .
Vibrant Technologies & Computers
Ā 
Data ware housing - Introduction to data ware housing process.
Vibrant Technologies & Computers
Ā 
Data ware housing- Introduction to data ware housing
Vibrant Technologies & Computers
Ā 
Salesforce - classification of cloud computing
Vibrant Technologies & Computers
Ā 
Salesforce - cloud computing fundamental
Vibrant Technologies & Computers
Ā 
SQL- Introduction to PL/SQL
Vibrant Technologies & Computers
Ā 
SQL- Introduction to advanced sql concepts
Vibrant Technologies & Computers
Ā 
SQL Inteoduction to SQL manipulating of data
Vibrant Technologies & Computers
Ā 
SQL- Introduction to SQL Set Operations
Vibrant Technologies & Computers
Ā 
Sas - Introduction to designing the data mart
Vibrant Technologies & Computers
Ā 
Sas - Introduction to working under change management
Vibrant Technologies & Computers
Ā 
SAS - overview of SAS
Vibrant Technologies & Computers
Ā 
Teradata - Architecture of Teradata
Vibrant Technologies & Computers
Ā 
Teradata - Restoring Data
Vibrant Technologies & Computers
Ā 

Recently uploaded (20)

PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
Ā 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
Ā 
PPTX
IoT Sensor Integration 2025 Powering Smart Tech and Industrial Automation.pptx
Rejig Digital
Ā 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
Ā 
PDF
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
Ā 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
Ā 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
Ā 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
Ā 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
Ā 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
Ā 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
Ā 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
Ā 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
Ā 
PDF
Software Development Methodologies in 2025
KodekX
Ā 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
Ā 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
Ā 
PPTX
Coupa-Overview _Assumptions presentation
annapureddyn
Ā 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
Ā 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
Ā 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
Ā 
Brief History of Internet - Early Days of Internet
sutharharshit158
Ā 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
Ā 
IoT Sensor Integration 2025 Powering Smart Tech and Industrial Automation.pptx
Rejig Digital
Ā 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
Ā 
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
Ā 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
Ā 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
Ā 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
Ā 
cloud computing vai.pptx for the project
vaibhavdobariyal79
Ā 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
Ā 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
Ā 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
Ā 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
Ā 
Software Development Methodologies in 2025
KodekX
Ā 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
Ā 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
Ā 
Coupa-Overview _Assumptions presentation
annapureddyn
Ā 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
Ā 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
Ā 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
Ā 

PHP - Introduction to Object Oriented Programming with PHP

  • 2. Introduction to Object Oriented Programming with PHP
  • 3. Object Oriented ConceptObject Oriented Concept ļ‚” Classes, which are the "blueprints" for an object and are the actual code that defines the properties and methods. ļ‚” Objects, which are running instances of a class and contain all the internal data and state information needed for your application to function. ļ‚” Encapsulation, which is the capability of an object to protect access to its internal data ļ‚” Inheritance, which is the ability to define a class of one kind as being a sub-type of a different kind of class (much the same way a square is a kind of rectangle).
  • 4. Creating ClassCreating Class • Let's start with a simple example. Save the following in a file called class.lat.php: <?php class Demo { } ?>
  • 5. Adding MethodAdding Method • The Demo class isn't particularly useful if it isn't able to do anything, so let's look at how you can create a method. <?php class Demo { function SayHello($name) { echo ā€œHello $name !ā€; } } ?>
  • 6. Adding PropertiesAdding Properties • Adding a property to your class is as easy as adding a method. <?php class Demo { public $name; function SayHello() { echo ā€œHello $this->$name !ā€; } } ?>
  • 7. Object InstantiationObject Instantiation • You can instantiate an object of type Demo like this: <?php require_once('class.lat.php'); $objDemo = new Demo(); $objDemo->name = ā€œBayuā€; $objDemo->SayHallo(); ?>
  • 8. Protecting Access toProtecting Access to Member VariablesMember Variables (1)(1)ļ‚” There are three different levels of visibility that a member variable or method can have : ļ‚§ Public ā–Ŗ members are accessible to any and all code ļ‚§ Private ā–Ŗ members are only accessible to the class itself ļ‚§ Protected ā–Ŗ members are available to the class itself, and to classes that inherit from it Public is the default visibility level for any member variables or functions that do not explicitly set one, but it is good practice to always explicitly state the visibility of all the members of the class. Public is the default visibility level for any member variables or functions that do not explicitly set one, but it is good practice to always explicitly state the visibility of all the members of the class.
  • 9. Protecting Access toProtecting Access to Member VariablesMember Variables (2)(2) • Try to change access level of property named ā€œnameā€ to private of previous code. • What the possible solution of this problem? • Make the getter and setter function... Always use get and set functions for your properties. Changes to business logic and data validation requirements in the future will be much easier to implement. Always use get and set functions for your properties. Changes to business logic and data validation requirements in the future will be much easier to implement.
  • 10. Class ConstantsClass Constants ļ‚” It is possible to define constant values on a per- class basis remaining the same and unchangeable. ļ‚” Constants differ from normal variables in that you don't use the $ symbol to declare or use them ļ‚” The value must be a constant expression, not (for example) a variable, a property, a result of a mathematical operation, or a function call
  • 11. Class Constants (cont.)Class Constants (cont.) <?php classĀ MyClass { Ā Ā Ā Ā constĀ constantĀ =Ā 'constantĀ value'; Ā Ā Ā Ā functionĀ showConstant()Ā { Ā Ā Ā Ā Ā Ā Ā Ā echoĀ Ā self::constantĀ .Ā "n"; Ā Ā Ā Ā } } echoĀ MyClass::constantĀ .Ā "n"; ?> <?php classĀ MyClass { Ā Ā Ā Ā constĀ constantĀ =Ā 'constantĀ value'; Ā Ā Ā Ā functionĀ showConstant()Ā { Ā Ā Ā Ā Ā Ā Ā Ā echoĀ Ā self::constantĀ .Ā "n"; Ā Ā Ā Ā } } echoĀ MyClass::constantĀ .Ā "n"; ?>
  • 12. Static KeywordStatic Keyword • Declaring class properties or methods as static makes them accessible without needing an instantiation of the class. • A property declared as static can not be accessed with an instantiated class object
  • 14. ContructorContructor • Constructor is the method that will be implemented when object has been initiated • Commonly, constructor is used to initialize the object • Use function __construct to create constructor in PHP <?php class Demo { function __construct { } } ?>
  • 15. DestructorDestructor • Destructor, is method that will be run when object is ended <?php class Demo { function __destruct { } } ?>
  • 16. InheritanceInheritance • There are many benefits of inheritance with PHP, the most common is simplifying and reducing instances of redundant code.
  • 17. Inheritance (2)Inheritance (2) class hewan { protected $jml_kaki; protected $warna_kulit; function __construct() { } function berpindah() { echo "Saya berpindah"; } function makan() { echo "Saya makan"; } } class hewan { protected $jml_kaki; protected $warna_kulit; function __construct() { } function berpindah() { echo "Saya berpindah"; } function makan() { echo "Saya makan"; } }
  • 20. Tugas (cont.)Tugas (cont.) ļ‚” Class product : ļ‚§ name ļ‚§ price ļ‚§ discount ļ‚” Class CDMusic : ļ‚§ artist ļ‚§ Genre ļ‚” Class CDRack ļ‚§ capacity ļ‚§ model
  • 21. Tugas (cont.)Tugas (cont.) ļ‚” CDMusic ļ‚§ Menuruni name, price dan discount dari Product ļ‚§ Price = price + 10% ļ‚§ Ada penambahan 5% pada discount ļ‚” CDRack ļ‚§ Menuruni name, price dan discount dari Product ļ‚§ Price = price + 15% ļ‚§ Tidak ada penambahan discount ļ‚” Buatlah code dalam PHP, serta simulasi untuk kasus tersebut!
  • 22. ThankThank You !!!You !!! For More Information click below link: Follow Us on: http://vibranttechnologies.co.in/php-classes-in- mumbai.html