OOP stands for object oriented programming. To implement OOP in PHP, class and its objects are used, and objects are created from class, where class hold data and functions, and object is used to access functions and data. PHP introduced OOP in PHP5.
OOP Characteristics
when a program is written using OOP, it has following advantages
Abstraction | This features Hide implementation details of a class. |
Encapsulation | Hold or binds data and function together. i.e. class. |
Inheritance | Acquiring parent class data and function in its child class. |
Polymorphism | To use single function for different task. |
To implement OOP in PHP, needs to create a class and its objects.
Class user defined data type to create class holds data and function in a single unit.
Procedure Oriented language | OOPS | USE |
---|---|---|
Data/variable | Data Members/Properties | Holds or store data |
Function | Member Function or Methods | Access or perform operations on member function |
Objects | Objects are used to access class members (variable & function). |
Constructor | Initializes data members with default value. |
Destructor | Frees memory by removing unused objects. |