constructor function
void __construct ([ mixed $args
[, $...
]])
PHP 5 allows the developer to define a method as a constructor in a class. Classes with constructors Call this method each time a new object is created, making it ideal for doing some initialization work before using the object.
If a constructor is defined in a subclass, the constructor of its parent class is not implicitly called. To execute the constructor of the parent class, you need to call Parent::__construct () in the constructor of the child class . If a subclass does not have a constructor defined, it inherits from the parent class like a normal class method (if it is not defined as private).
Destructors
void __destruct ( void)
PHP 5 introduces the concept of destructors, similar to other object-oriented languages such as C + +. Destructors are removed when all references to an object are deleted or executed when an object is explicitly destroyed.
As with constructors, the destructor of the parent class is not called by the engine. To execute a destructor for a parent class, you must explicitly call Parent::__destruct () in the destructor body of the subclass . Also, as with constructors, subclasses inherit the parent class if they do not have a destructor defined by themselves.
Destructors are called even when the script is run with exit (). Calling exit () in the destructor will abort the operation of the rest of the shutdown operation.
Throwing an exception in a destructor (called when the script terminates) causes a fatal error.
PHP Constructors and destructors