Wednesday, 18 April 2018

PHP Object Oriented Programming Concepts

PHP Object Oriented Programming Concepts

Class vs Object

Class is like your house blueprint. Before your house is build up there is a house blueprint. It is 
not an certain house, but a plan how this house will look like, how many rooms it will have and 
so on. Then the house will be build up by giving the blueprint. The blueprint is a class and your
 actual home is an object. Learn  OOPs concepts in Detail with PHP Training in Chandigarh.
A few key points to keep in mind:
  • Class is universal, whereas Object is defined
  • Class defines properties/functions of an Object
  • Object is an instance of a Class
  • You can instantiate an object, but not a Class
PHP Training in Chandigarh

 PHP Class

Class is contains all the properties and methods. In this simple class. $postCode is a equity 
and ringBell() is a method. They are all prefixed with a clarity keyword (public).
Class House {

    public $postCode = “560121”;

    public function ringBell() {
        echo “Ding Dang Dong”;


Every method and property has its own visibility. Here we have  three types of visibility in PHP. 
They are announced by keywords public, protected and private. Each one of them authority how 
a method or property can be approach by outsiders.
Public: It allows everyone from outside access its method. This is the default visibility in PHP 
class when no keywords are added to a method.
Protected: It only allows itself or children classes to approach its method.
Private: It does not allow anyone except itself to approach its method.

Inheritance in PHP

It lets subclass inherits essincial of the parent class. Parent class choose what and how these
 methods to be inherited by declared visibility.

Polymorphism in PHP

The arrangement of a single interface to attributes of different types.  PHP is adept to actions
 objects moderation depending on data type or class. This powerful feature allows you to write
 interchangeable objects that sharing the same interface.

Encapsulation in PHP
Encapsulation is used to hide the values or state of a analytic data object center a class, 
avoid unauthorized parties direct access to them. It is  approach that motivates us to think 
through a method/class authority and hide its internal implementation all the details accordingly. 
This will make it easy to modify the internal code in a long run without touching other part of the 
system. Visibility is the mechanism for encapsulation.

Abstraction in PHP

Abstraction is the approach that focus on the particulars and detailed application of things, to the
 types of things,the operations available ,etc, thus making the programming simple, more basic, 
and more abstract. It is like a archive instead of a condition.

Interface vs Abstract class in PHP


Interface declares what methods a class must have without having to implement them. Any class 
that appliance the alliance will have to implement particulars of those declared methods. Interface 
is not a class, so you cannot instruct an interface.
Abstract class
Abstract class is able to enforce subclasses to implement methods similar to interface.
 When a method is declared as abstract in an abstract class, its derived classes must 
implement that method.Get more Knowledge about OOP’s Concepts 
 with PHP Training in Chandigarh.

For Infographic Visit:-


Post a Comment