PHP OOP Introduction In Hindi

📔 : PHP 🔗

OOP Object Oriented Programing का ही sort form है। Java / JavaScript या C ++ की तरह ही PHP भी OOP Concept को support करती है। OOP concept PHP Version 5 में add किया गया था , उससे पहले PHP में OOP का कोई concept नहीं था।

OOP (Object Oriented Programing) Classes और Objects पर based एक Programming Paradigm / Approach है। Simple भाषा में कहें तो OOP (Object Oriented Programing) Real World Entity/Object को Programming में represent करने का method / way है।

Real World Entity को ही Programing में Class / Object द्वारा represent किया जाता है। Entity की कुछ Properties या Behavior होता है जिसे Programing में Class variables & methods से represent किया जाता है।

What is class

Class किसी Object के लिए एक Blueprint होता है।
For Example -
Car - एक blueprint है ,
Car के different - different brand (Maruti, Ford , Audi etc. ) Objects हैं।

PHP OOP Principles

PHP में मुख्य रूप 3 OOP Principles हैं -

  1. Inheritance

  2. Encapsulation

  3. Abstraction

  4. Polymorphism

PHP Inheritance

किसी class को या Class की properties / behavior को extend करना Inheritance कहते हैं। जिस class को extend किया गया है उसे Parent Class , जिस class के द्वारा extend किया गया है उसे Child Class कहते हैं।
Extend करने पर Child Class में लगभग बो सभी properties / methods होंगे जो Parent Class में हैं। Read More...

हालाँकि Parent Class में यह define किया जा सकता है कि कौन सी properties या methods को Child Class access कर सकती है।

PHP Encapsulation

data members को single Object में bind करना ही encapsulation कहलाता है। Encapsulation class में defined variables & methods को protect करने की protection mechanism होती है।

encapsulation mechanism की help से हम data members पर अपनी need के according access restrictions define करते हैं , जिससे data को बाहर से access नहीं किया जा सके , PHP में encapsulation achieve करने के लिए दो चीज़ों का use करते हैं -

  1. private keyword का use करके members को private बनाते है।

  2. और setter & getter methods का use data को set / get करने के लिए करते हैं।

Read More About It Encapsulation

PHP Abstraction

किसी भी class के लिए internal implementation details को hide करना & सिर्फ Operational process show करना ही Abstraction कहते हैं।

PHP Polymorphism

simple भाषा में समझें तो किसी single task को different-different way /methods से perform करना ही Polymorphism कहते हैं। Basically Polymorphism दो शव्दों से मिलकर बना है , Poly(Many) & morph (Forms). यह दो type की होती है -

  1. Run Time (Method Overriding).

  2. Compile Time (Method Overloading)

Note - Compile Time (Method Overloading) PHP support करती नहीं है।

Method Overriding

Parent class में define किया गया method Child Class में भी define करना ही Method Overriding कहलाता है। Basically ये scenario Inheritance के साथ perform किया जाता है।

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)

Get connected with me. :) LinkedIn Twitter Instagram Facebook

b2eprogrammers