What is PHP Constructor in Hindi

PHP In Hindi – PHP Constructor And Destructor In Hindi

PHP

PHP In HindiPHP Constructor And Destructor In HindiPHP Constructor Ek special type Ka member function Hota Hai, Jo Aapne class Ke Name Jaisa Hota Hai And PHP Destructor Ye Bhi Ek special type member function Hota Hai, Jo object Ko destroy Kar Deta Hai |

Previous Post Also Read :- PHP Classes/Objects

PHP Constructor And Destructor In Hindi

Contents

Is Post Me Ham Constructor And Destructor In Hindi Ke Bare Me Janne Wale Hai Wo Bhi Step By Step In Hindi |

Constructor And Destructor In PHP In Hindi Ka Istemal Keval OOPs Me Hi Hota Hai |

PHP Constructor in Hindi

What is PHP Constructor in Hindi – PHP Constructor Ek special type Ka member function Hota Hai, Jo Aapne class Ke Name Jaisa Hota Hai Jis Class Ka Constructor Bana Ho, Agar Usi Class Ka Jab Object Jab Banta hai | Tab Vo Automatically Call Hota Hai | Constructor ka koi bhi return type nhi hota hai | Void Bhi Return Nhi Karta Hai, Agar Koi Value Ko Initialize Karna Ho to Alag se Uska Member Function Bana Kar Use Object Se Sath Access Karta Padta Hai | Constructor Ye Kam Sirf Object banate Waqt hi kar deta hai |

Constructor ko Ham Class Ke Under And Bahar Bhi Define Kar Sakte Hai |

PHP me Constructor Ko Create Karne Ke Liye __constructor() Functions Ka Istemal Karna Hota Hai |

Example:

PHP Class Ko Define Kar Diya Hai.Lekin Ab Ham Class Ke Under Function Create karte Hain __construct for Construct Karne ke Liye And get_name() for get Karne Ke Liye String Variable Ko |

<?php
class MasterPrograming {
  // Properties
  public $name;

  // Methods
  function __construct($name) {
    $this->name = $name;
  }
  function get_name() {
    return $this->name;
  }
}

$dk = new MasterPrograming("Danish Ali");

echo $dk->get_name();
?>

Aapko Pata Hoga Ki Hamne Class MasterPrograming Create Kiya Tha Upper Or Ab Hamne Us Class Ka Ek $dk Obj Create Kiya Hai | Aap Kitne Bhi object create Kar Sakte Hai |

Output:

Danish Ali

PHP Destructor In Hindi

Destructor Ye Ek Special Type Ka Member Function Hota Hai, Jo Object Ko Destroy ya Delete Kar Deta Hai | Jab Object Program Se Bahar Ho Jata Hai,tab Destructor Automatically Call Hota Hai | Destructor Or Constructor Ke Parameters Nhi Hote |

Constructor ko Ham Class Ke Under And Bahar Bhi Define Kar Sakte Hai |

PHP me Constructor Ko Create Karne Ke Liye __construct() Functions Ka Istemal Karna Hota Hai |

PHP me Destructor Ko Create Karne Ke Liye __destruct() Functions Ka Istemal Karna Hota Hai |

Example:

<?php
class MasterPrograming {
  // Properties
  public $name;

  // Methods
  function __construct($name) {
    $this->name = $name;
  }

  function __destruct(){
  	echo "The MasterPrograming is {$this->name}.";
  }

}

$dk = new MasterPrograming("Danish Ali");
?>

Output:

The MasterPrograming is Danish Ali.

Friends Mujhe Umeed Hai Ki Aapko Constructor And Destrutor in PHP in Hindi Ke Bare Mai 100% Jankari Ho Gayi Hogi | Agar Aapko Learn Karne Main Dikkat Aa Rahi Hai To Aap Mere Se Contact Kar Sakte Hai |

Yadi Aapne  HTML Full Course  And CSS Full Course And Python Full Course And PHP Full Course Nhi Read Kiya Hai To Aap Vah Bhi Read Kar Sakte Hai |

Leave a Reply

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