OOP, यानी Object Oriented Programming, एक ऐसा Programming Approach है जो Classes और Objects पर आधारित होता है। यह तरीका हमें Real-World Entities (जैसे Car, Bank Account, Student, आदि) को Programming में Represent करने की सुविधा देता है।
जैसे Java, JavaScript या C++ में OOP का इस्तेमाल किया जाता है, वैसे ही PHP भी Object Oriented Programming को सपोर्ट करता है। हालांकि, PHP में OOP का कॉन्सेप्ट PHP Version 5 से जोड़ा गया था। इससे पहले की PHP वर्ज़न्स पूरी तरह से Procedural Programming पर आधारित थे।
Object Oriented Programming की परिभाषा
OOP (Object-Oriented Programming) is a programming paradigm that organizes software design around objects rather than functions and logic. It focuses on creating reusable, modular code by using classes and objects.
OOP में Classes और Objects क्या होते हैं?
Class: यह एक Blueprint होती है जिसमें किसी Entity की Properties (Variables) और Behaviors (Methods/Functions) को परिभाषित किया जाता है।
Object: यह Class का एक Instance होता है। यानी Class के आधार पर बनाया गया वास्तविक Object, जो Memory में एक Entity को Represent करता है।
उदाहरण:
Car एक क्लास है। इसके अंदर कई ब्रांड के ऑब्जेक्ट्स बन सकते हैं जैसे: Maruti, Ford, Audi आदि। हर ऑब्जेक्ट के अपने फीचर्स और व्यवहार हो सकते हैं लेकिन मूल स्ट्रक्चर एक जैसा होगा।
PHP में OOP के मुख्य Principles
PHP में OOP के चार प्रमुख स्तंभ होते हैं:
- Inheritance
- Encapsulation
- Abstraction
- Polymorphism
Inheritance
Inheritance का अर्थ है किसी क्लास की properties और methods को दूसरी क्लास में उपयोग करना।
- Parent Class: मूल क्लास जिसे Extend किया जाता है।
- Child Class: वह क्लास जो Parent की Properties और Methods को अपनाती है।

Encapsulation
Encapsulation का मतलब है Data और Functions को एक जगह सुरक्षित रखना।
PHP में इसे प्राप्त करने के लिए दो चीज़ों का प्रयोग किया जाता है:
privatekeyword का उपयोग करके Properties/Methods को बाहर से access करने से रोका जाता है।- Getter और Setter methods के द्वारा डेटा को सुरक्षित तरीके से एक्सेस किया जाता है।
Abstraction
Abstraction का मतलब होता है अनावश्यक जानकारी को छुपाना और केवल आवश्यक जानकारी दिखाना।
Polymorphism
Polymorphism का अर्थ है एक ही कार्य को विभिन्न तरीकों से करना। यह दो प्रकार का होता है:
- Compile Time Polymorphism (Method Overloading) – PHP इसे सपोर्ट नहीं करता।
- Run Time Polymorphism (Method Overriding) – PHP इसे सपोर्ट करता है।
PHP में OOP का उपयोग करके हम अपने कोड को ज़्यादा संरचित, सुरक्षित और मॉड्यूलर बना सकते हैं। यदि आप बड़े प्रोजेक्ट्स या स्केलेबल एप्लिकेशन पर काम कर रहे हैं, तो OOP Concepts को समझना और प्रयोग करना बेहद जरूरी है।

Welcome to HindiTutorials, your go-to platform for learning and mastering concepts in Hindi! Our mission is to make education accessible and simple for everyone by providing high-quality tutorials on programming, technology, and various other topics.