Object-Oriented Programming (PHP OOPS)

OOPs Dependencies

  • Class
  • Object
  • Inheritance
  • Polymorphism
  • Overloading
  • Overriding
  • Abstraction
  • Constructor
  • Destructor

Object oriented programming language is the concept of oops programming language.

CLASS : – Class is a group of Values with a set of Operations we can also say class is a blue-print(Architecture) object . Class can be used to seprate the data from relative data . we can think of a class as a template for making many instances of the same kind of object . ( instances – Objects are also known as instance(background process also know as instance )

Example Class -: a programmer can create a car class which describe a car. This class can contain the properties of a car (color, model, year, etc.)

 class FetchDataTest { 
     private $db; 
     private $id; 
 function __construct() 
 db = new Database();(Object)     }    
 public function FunctionnameTest(){        
 $test = $this->db->execute("SELECT * from testabc(tablename)");        
 $results = $this->db->getResults($test);         
return $results;   

Object: – Object is a Class types variable it is the components of oops , the new operator used to create an Object.

Example : $object = new database(); $this -> db = new Database();

Inheritance : Drive a new class from an old class called as Inheritance ,we can create a new class with the help of old class known as Inheritance (Extends keywords used to inherit the class) , Inheritance specially used for reduce the number of code.

 Example : - son can used Father Properties so same as in Inheritance .
 Class Father {
         member of class father
 Class son extends Father{
 member of class son

Polymorphism : One things has many Form knows as Polymrphism ,(many types , many form)

Example : -   Just make a call to toll free number ,  During the call they give us a suggestion English for click 1 , Hindi for click 2 and so on 

Overloading :- Two or more function having same but the argument will be different

Example : real time Example assign some extra tasks to someone known as Overloading , same name but differ in the type of input parameter .

functions that have similar signatures .   only overload methods using the magic method __call. 
Class Test {
public FunctionTestA1(hi){
     echo "hi";
 Class TestB1 {
public FunctionTestA1(Hello){
     echo "Hello";

Overriding : – Overriding is to replace parent method in child class ,Two method with same name and same parameter known as Overriding.

 public class Forestanimal {
      public function readytoSpeak() {
          echo "Cat Speaking";

   // This is overloading the method  readytoSpeak .
      public function readytoSpeak($sound) {
        echo  $sound;

Abstraction : Require things will be Display Other used to hide .

Example: we have a Complete Employees Database Table , Name ,Address ,Department ,and so on .i just only need to fetch employees name and department.

Sql> SELECT name, department FROM Employees. so here we have get only require things other things we don't need .

Constructor : constructor is the member function of class that automatically called when an object created to other class.

Example : __construct ( ) : –

suppose page1.php 

class FetchData
private $db;
private $id;
function __construct()
$this->db = new Database();

$obj = new FetchData();

Leave a Reply

Your email address will not be published. Required fields are marked *