Skip to main content

Openings for different technoogies.

What is Constructor and Destructor?

 Constructor:

Constructor is a special type of function which will be called automatically whenever there is any object created from a class.

//Old (PHP4) class myClass{ function myClass(){ // Define logic in constructor } }
//New (PHP5+) class myClass{ function __construct(){ // Define logic in constructor } }
Note- Old style constructors are DEPRECATED in PHP 7.0, and will be removed in a future version. You should always use __construct() in new code.
Destructor:

Destructor is a special type of function which will be called automatically whenever any object is deleted or goes out of scope.

class myClass{ function __construct(){ // Define logic in constructor } function __destruct(){ // this is destructor } }
Types of constructors:
  1. Default constructor
  2. A constructor without any parameters is called a default constructor.

  3. Parameterized constructor
  4. A constructor with at least one parameter is called a parametrized constructor.

    class Person{ public $name; public $address; public function __construct($name){ // parameterized constructor with name argument $this->name = $name; } } $perObj1 = new Person("Full Stack Tutorials"); // parameterized constructor with name argument echo $perObj1->name; //Output: Full Stack Tutorials
  5. Copy Constructor
  6. class Person{ public $name; public $address; public function __construct($name){ // parameterized constructor with name argument $this->name = $name; } public function __clone(){ } } $perObj1 = new Person("Full Stack Tutorials"); // parameterized constructor with name argument $perObj2 = clone $perObj1; // copy constructor initialize $perObj2 with the values of $perObj1 echo $perObj2->name; //Output: Full Stack Tutorials
  7. Static Constructor
  8. Private Constructor
  9. Purpose of Private Constructor: It ensures that there can be only one instance of a Class and provides a global access point to that instance and this is common with The Singleton Pattern.

    class myClass { private static $instance; private function __construct() { } public static function get_instance() { if (!self::$instance) self::$instance = new myClass(); return self::$instance; } }

Comments

Popular posts from this blog

Openings for different technoogies.

 

Walk in for Networking Executives On 29th Nov

Company        Infosys BPO Ltd Website          www.infosysbpo.com Eligibility        Graduates/Diploma Experience     1-3 Years Location         Chennai Infosys BPO Ltd Job Role: Networking Executives Job Summary : 1. Working experience in supporting network related queries 2. Knowledge on switches, Rouers, Hubs, LAN'S,WAN'S etc is preferred QUALIFICATION: 1. Only graduates with 10+2+3 2. Diploma 10+2+3 SKILLSETS: Good communication skills. Strong analytical and problem solving skills. EXPERIENCE 18 to 36 months experience in the relevant field only OTHERS Flexibility to work in shifts Walkins for Networking Executives on 29th Nov 2012 *****Interview Slots******* ******10:30 AM & 1:00 PM & 3:00 PM***** Walk-In Venue: Infosys BPO 3rd Floor, Hardy Towers Ramanujam IT Park Next to Tidal Taramani (Tirumanviyur...

SBI Hiring Probationary Officers

Company        SBI(State Bank Of India) Website          www.sbi.co.in Eligibility        Any Degree Experience     Freshers Location         Anywhere in India SBI(State Bank Of India) Job Role: Probationary Officers (POs) Job Summary : Eligibility Criteria: Graduation in any discipline from a recognised University or any equivalent qualification recognised as such by the Central Government. Age Limit: As on 01.01.2013 Not below 21 years and not above 30 years as on 01.01.2013 i.e candidates must have been born not earlier than 02.01.1983 and not later than 01.01.1992 (both days inclusive) ONLINE REGISTRATION OF APPLICATION: 30.01.2013 TO 23.02.2013 PAYMENT OF FEES - ONLINE : 30.01.2013 TO 23.02.2013 PAYMENT OF FEES - OFFLINE : 01.02.2013 TO 28.02.2013 DATE OF WRITTEN EXAMINATION : 28.04.2013 More Details: http://w...