CONSTRUCTOR

  • PHP 5 allows developers to declare constructor methods for classes.
  • Constructor is suitable for any initialization that the object may need before it is used.
  • We can design constructor using "__construct" or same name as class name.
  • Parent constructors are not called implicitly if the child class defines a constructor. In order to run a parent constructor, a call to parent::__construct().

Example 1

Output:

CONSTRUCTOR

Example 2

Output:

CONSTRUCTOR
Next Topic




Contact US

Email:[email protected]

OOPs Constructor
10/30