Loading

Object Oriented Programming in PHP

Object-oriented programming is an approach to programming where objects and classes are used.PHP start support Object-Oriented Programming from version PHP4. But from version PHP5 it becomes very advance because the object model was rewritten for better performance and more features. From PHP5 we can say PHP 5 has a full object model. Now PHP7 comes with more features of Object-oriented Programming.
In this tutorial, we will learn all basic concepts of Object-oriented programming and learn how to implement object-oriented programming in PHP.
Object:- An object is a software bundle of variables and related methods. Objects have states and behaviors. Example:- Cat has a state name, color, breed, hungry, etc. and behavior fetching, cat voice, etc.
Class:- The user-defined objects are created using the class keyword. That means, In object-oriented programming, a class is a construct or prototype from which objects are created.
PHP provides a class keyword for creating a class.
The following example will explain the PHP class and how to instantiate an object.
class Animal {
//property statement
private $bried;
private $havit;
//method
function getbried{
}
}
//instantiate object
$myobj = new Animal;
To create an instance of a class, the new keyword must be used in PHP.
Attributes:- In object-oriented programming class and object have attributes. Characteristics that describe the object (sometimes referred to as properties).
That means, Attribute store information about the instance.
Methods:- Operations or actions that objects perform or operations which are performed to an object. Sometimes referred to as behaviors. That means, A method defines the behavior of the objects that are created from the class.
Instance:- An object created from a class (is an instance of that class). That means, An Instance is simply a variation of an object created from a class.
Appropriate definition, An instance, in object-oriented programming (OOP), is a specific realization of any object. An object may be varied in a number of ways. Each realized variation of that object is an instance. The creation of a realized instance is called instantiation.
Abstraction:- Abstraction is one of the core concepts of Object-Oriented Programming. Refers to hiding the internal details of an object from the user. It helps to reduce programming complexity and effort.
Encapsulation:- Encapsulation is one of the fundamental concepts in object-oriented programming. It refers to the combining of an object’s attributes and behaviors into a single package, i.e. a class. The programmer than can then access the methods and properties of the class without having to understand the implementation.
Inheritance:- Inheritance is a mechanism in which one class acquires the property of another class. That means, it refers to the capability of creating a new class from an existing class.
Base Class:- A base class is a class, in an object-oriented programming language, from which other classes are derived. That means, an originally created class, along with its attributes and behaviors. A class from which another class inherits its attributes and behaviors.
Derived Class:- A derived class is a class created or derived from another existing class. The existing class from which the derived class is created through the process of inheritance is known as a base class or superclass. That means, a newly created class, derived from a base class which inherits all of the attributes and behaviors from the base class, but may have additional attributes and behaviors associated with it.
What is UML?
UML stands Modifying Modeling Language. It is a technique for design and document Object-Oriented Programming. Like Class diagram, ER diagram, etc.

Share with:


4+

One thought on “Object Oriented Programming in PHP

Leave a Reply

Connect with:




z35W7z4v9z8w