What is OOPS concept in php?
OOP (Object-oriented programming) is a programming paradigm based on the concept of “objects”, which can contain data and code: data in the form of fields (often known as attributes or properties), and code, in the form of methods. Many of the most widely used programming languages (such as C++, Java, Python, etc.) are multi-paradigm and they support object-oriented programming to a greater or lesser degree, typically in combination with imperative, procedural programming.
Object-oriented programming uses objects, but not all of the associated techniques and structures are supported directly in languages that claim to support OOP. It performs operations on operands.
PHP introduced object-oriented programming features since version 5.0. Object-Oriented programming is one of the most popular programming paradigms based on the concept of objects and classes. It helps you to structure a complex application into a simpler and more maintainable structure.
In this blog, we will be explaining some of the Object-Oriented Programming concepts in PHP. PHP is a server-side scripting language, mainly used for web development but also used as a general-purpose programming language.
PHP Object Oriented Concepts
-> Class
-> Object
-> Member Variable
-> Member function
-> Constructor
-> Inheritance
-> Abstraction
-> Encapsulation
-> Polymorphism
- Class
PHP being an object oriented programming language, allows creation of classes and objects to follow the object oriented programming paradigm while developing any software or application. A class is a user-defined data type which includes local variables and local methods.
- Object
Object is an individual instance of the data structure defined by a class.When class is created, we can create any number of objects in that class. The object is created with the help of the new keyword.
- Member Variable
When the object is created we can access the variables and method function of the class with the help of operator ‘->, accessing the method is done to get the information of that method. This data will be invisible to the outside of the class.
- Member Function
These are the function defined inside a class and are used to access object data.
- Constructor
HP allows you to declare a constructor method for a class with the name __construct(). Typically, you use the constructor to initialize the properties of the object. It refers to a special type of function which will be called automatically whenever there is an object formation from a class.
- Inheritance
The main purpose of inheritance is re-usability. When a class is defined by inheriting existing function of a parent class then it is called inheritance. This is very useful when we have to provide common functionality such as adding, updating and deleting data from the database.
- Abstraction
Any representation of data in which the implementation details are hidden (abstracted). * Encapsulation − refers to a concept where we encapsulate all the data and member functions together to form an object.
- Encapsulation
In PHP, encapsulation utilized to make the code more secure and robust. Using encapsulation, we are hiding the real implementation of data from the user and also does not allow anyone to manipulate data members except by calling the desired operation.
- Polymorphism
This is an object oriented concept where same function can be used for different purposes. For example function name will remain same but it make take different number of arguments and can do different task. Simplify maintaining applications and making them more extendable.
Comments 1