Javatpoint Logo
Javatpoint Logo

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





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA