SlideShare uma empresa Scribd logo
1 de 22
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
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

Mais conteúdo relacionado

Mais procurados (20)

jQuery
jQueryjQuery
jQuery
 
Database Connectivity in PHP
Database Connectivity in PHPDatabase Connectivity in PHP
Database Connectivity in PHP
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScript
 
Java script
Java scriptJava script
Java script
 
PHP - Introduction to File Handling with PHP
PHP -  Introduction to  File Handling with PHPPHP -  Introduction to  File Handling with PHP
PHP - Introduction to File Handling with PHP
 
Statements and Conditions in PHP
Statements and Conditions in PHPStatements and Conditions in PHP
Statements and Conditions in PHP
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
 
JAVA AWT
JAVA AWTJAVA AWT
JAVA AWT
 
HTML Forms
HTML FormsHTML Forms
HTML Forms
 
Asp.NET Validation controls
Asp.NET Validation controlsAsp.NET Validation controls
Asp.NET Validation controls
 
Php introduction
Php introductionPhp introduction
Php introduction
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivity
 
Methods in Java
Methods in JavaMethods in Java
Methods in Java
 
Javascript arrays
Javascript arraysJavascript arrays
Javascript arrays
 
Php with MYSQL Database
Php with MYSQL DatabasePhp with MYSQL Database
Php with MYSQL Database
 
PHP variables
PHP  variablesPHP  variables
PHP variables
 
Wrapper class
Wrapper classWrapper class
Wrapper class
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Java constructors
Java constructorsJava constructors
Java constructors
 

Destaque (13)

Object Oriented Programming in PHP
Object Oriented Programming in PHPObject Oriented Programming in PHP
Object Oriented Programming in PHP
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
 
PHP Classes and OOPS Concept
PHP Classes and OOPS ConceptPHP Classes and OOPS Concept
PHP Classes and OOPS Concept
 
OOP in PHP
OOP in PHPOOP in PHP
OOP in PHP
 
A Gentle Introduction To Object Oriented Php
A Gentle Introduction To Object Oriented PhpA Gentle Introduction To Object Oriented Php
A Gentle Introduction To Object Oriented Php
 
Java Servlets & JSP
Java Servlets & JSPJava Servlets & JSP
Java Servlets & JSP
 
C vs c++
C vs c++C vs c++
C vs c++
 
APACHE TOMCAT
APACHE TOMCATAPACHE TOMCAT
APACHE TOMCAT
 
JSP
JSPJSP
JSP
 
Tomcat and apache httpd training
Tomcat and apache httpd trainingTomcat and apache httpd training
Tomcat and apache httpd training
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
 
Php Presentation
Php PresentationPhp Presentation
Php Presentation
 
Asp.net.
Asp.net.Asp.net.
Asp.net.
 

Semelhante a Introduction to OOP Concepts with PHP

OOPS IN PHP.pptx
OOPS IN PHP.pptxOOPS IN PHP.pptx
OOPS IN PHP.pptxrani marri
 
ABAP Object oriented concepts
ABAP Object oriented conceptsABAP Object oriented concepts
ABAP Object oriented conceptsDharmeshKumar49
 
Introduction to objective c
Introduction to objective cIntroduction to objective c
Introduction to objective cSunny Shaikh
 
Object Oriented Programming C#
Object Oriented Programming C#Object Oriented Programming C#
Object Oriented Programming C#Muhammad Younis
 
Synapseindia object oriented programming in php
Synapseindia object oriented programming in phpSynapseindia object oriented programming in php
Synapseindia object oriented programming in phpSynapseindiappsdevelopment
 
System_Verilog_OOPS_Concepts.pdf
System_Verilog_OOPS_Concepts.pdfSystem_Verilog_OOPS_Concepts.pdf
System_Verilog_OOPS_Concepts.pdfPoothan
 
UNIT - IIInew.pptx
UNIT - IIInew.pptxUNIT - IIInew.pptx
UNIT - IIInew.pptxakila m
 
Object-oriented Analysis, Design & Programming
Object-oriented Analysis, Design & ProgrammingObject-oriented Analysis, Design & Programming
Object-oriented Analysis, Design & ProgrammingAllan Mangune
 
Learn C# Programming - Classes & Inheritance
Learn C# Programming - Classes & InheritanceLearn C# Programming - Classes & Inheritance
Learn C# Programming - Classes & InheritanceEng Teong Cheah
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingAhmed Swilam
 
Lecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptxLecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptxShaownRoy1
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rdConnex
 
Object oriented approach in python programming
Object oriented approach in python programmingObject oriented approach in python programming
Object oriented approach in python programmingSrinivas Narasegouda
 
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
 
Object-oriented programming
Object-oriented programmingObject-oriented programming
Object-oriented programmingNeelesh Shukla
 

Semelhante a Introduction to OOP Concepts with PHP (20)

Only oop
Only oopOnly oop
Only oop
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
OOPS IN PHP.pptx
OOPS IN PHP.pptxOOPS IN PHP.pptx
OOPS IN PHP.pptx
 
ABAP Object oriented concepts
ABAP Object oriented conceptsABAP Object oriented concepts
ABAP Object oriented concepts
 
Introduction to objective c
Introduction to objective cIntroduction to objective c
Introduction to objective c
 
Object Oriented Programming C#
Object Oriented Programming C#Object Oriented Programming C#
Object Oriented Programming C#
 
Synapseindia object oriented programming in php
Synapseindia object oriented programming in phpSynapseindia object oriented programming in php
Synapseindia object oriented programming in php
 
System_Verilog_OOPS_Concepts.pdf
System_Verilog_OOPS_Concepts.pdfSystem_Verilog_OOPS_Concepts.pdf
System_Verilog_OOPS_Concepts.pdf
 
Php oop (1)
Php oop (1)Php oop (1)
Php oop (1)
 
UNIT - IIInew.pptx
UNIT - IIInew.pptxUNIT - IIInew.pptx
UNIT - IIInew.pptx
 
Object-oriented Analysis, Design & Programming
Object-oriented Analysis, Design & ProgrammingObject-oriented Analysis, Design & Programming
Object-oriented Analysis, Design & Programming
 
Learn C# Programming - Classes & Inheritance
Learn C# Programming - Classes & InheritanceLearn C# Programming - Classes & Inheritance
Learn C# Programming - Classes & Inheritance
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented Programming
 
Lecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptxLecture-10_PHP-OOP.pptx
Lecture-10_PHP-OOP.pptx
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rd
 
Object oriented approach in python programming
Object oriented approach in python programmingObject oriented approach in python programming
Object oriented approach in python programming
 
Beginners Guide to Object Orientation in PHP
Beginners Guide to Object Orientation in PHPBeginners Guide to Object Orientation in PHP
Beginners Guide to Object Orientation in PHP
 
Object-oriented programming
Object-oriented programmingObject-oriented programming
Object-oriented programming
 
oopusingc.pptx
oopusingc.pptxoopusingc.pptx
oopusingc.pptx
 

Mais de Vibrant Technologies & Computers

Data ware housing - Introduction to data ware housing process.
Data ware housing - Introduction to data ware housing process.Data ware housing - Introduction to data ware housing process.
Data ware housing - Introduction to data ware housing process.Vibrant Technologies & Computers
 

Mais de Vibrant Technologies & Computers (20)

Buisness analyst business analysis overview ppt 5
Buisness analyst business analysis overview ppt 5Buisness analyst business analysis overview ppt 5
Buisness analyst business analysis overview ppt 5
 
SQL Introduction to displaying data from multiple tables
SQL Introduction to displaying data from multiple tables  SQL Introduction to displaying data from multiple tables
SQL Introduction to displaying data from multiple tables
 
SQL- Introduction to MySQL
SQL- Introduction to MySQLSQL- Introduction to MySQL
SQL- Introduction to MySQL
 
SQL- Introduction to SQL database
SQL- Introduction to SQL database SQL- Introduction to SQL database
SQL- Introduction to SQL database
 
ITIL - introduction to ITIL
ITIL - introduction to ITILITIL - introduction to ITIL
ITIL - introduction to ITIL
 
Salesforce - Introduction to Security & Access
Salesforce -  Introduction to Security & Access Salesforce -  Introduction to Security & Access
Salesforce - Introduction to Security & Access
 
Data ware housing- Introduction to olap .
Data ware housing- Introduction to  olap .Data ware housing- Introduction to  olap .
Data ware housing- Introduction to olap .
 
Data ware housing - Introduction to data ware housing process.
Data ware housing - Introduction to data ware housing process.Data ware housing - Introduction to data ware housing process.
Data ware housing - Introduction to data ware housing process.
 
Data ware housing- Introduction to data ware housing
Data ware housing- Introduction to data ware housingData ware housing- Introduction to data ware housing
Data ware housing- Introduction to data ware housing
 
Salesforce - classification of cloud computing
Salesforce - classification of cloud computingSalesforce - classification of cloud computing
Salesforce - classification of cloud computing
 
Salesforce - cloud computing fundamental
Salesforce - cloud computing fundamentalSalesforce - cloud computing fundamental
Salesforce - cloud computing fundamental
 
SQL- Introduction to PL/SQL
SQL- Introduction to  PL/SQLSQL- Introduction to  PL/SQL
SQL- Introduction to PL/SQL
 
SQL- Introduction to advanced sql concepts
SQL- Introduction to  advanced sql conceptsSQL- Introduction to  advanced sql concepts
SQL- Introduction to advanced sql concepts
 
SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data   SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data
 
SQL- Introduction to SQL Set Operations
SQL- Introduction to SQL Set OperationsSQL- Introduction to SQL Set Operations
SQL- Introduction to SQL Set Operations
 
Sas - Introduction to designing the data mart
Sas - Introduction to designing the data martSas - Introduction to designing the data mart
Sas - Introduction to designing the data mart
 
Sas - Introduction to working under change management
Sas - Introduction to working under change managementSas - Introduction to working under change management
Sas - Introduction to working under change management
 
SAS - overview of SAS
SAS - overview of SASSAS - overview of SAS
SAS - overview of SAS
 
Teradata - Architecture of Teradata
Teradata - Architecture of TeradataTeradata - Architecture of Teradata
Teradata - Architecture of Teradata
 
Teradata - Restoring Data
Teradata - Restoring Data Teradata - Restoring Data
Teradata - Restoring Data
 

Último

Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 

Último (20)

Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 

Introduction to OOP Concepts with PHP

  • 1.
  • 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
  • 13.
  • 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