Constructor and Destructor in PHP?
Constructor
The constructor is the special type of method that runs automatically when an object is created of this class and Constructor are three types first is default constructor that has no parameters and the second type is the parameterized constructor and third is a copy constructor accepts the address of the other objects as a parameter.
syntax in PHP -:
- function __construct() { }//default __(double underscore)
- function __construct(parameters) { } //parameterized
- Copy Constructor click this link
Example - :
Destructor
The destructor is also a special type of method that runs when all code is executed or when an instance(Object) of the class is deleted from the memory.
The destructor does not take any parameters.
Example -:
No comments