Home >> PHP >> What is constructor in PHP

What is constructor in PHP

* Constructor is a special type of  function that does not return any value externally and it is responsible for initialize the Object.

* Internally it returns, the reference id of the object.

* Constructor function automatically called when creat object of class.

* Use by magic method __contruct().

* Create constructor  function public because accessible from outside of the class.


class A {
       function A(){
              echo "User Defined Constructor";
              echo "Predefined Defined Constructor";
$obj=new A();

Predefined Defined Constructor

Post Your Comment

Next Questions
Why use constructor
Predefined constructor
Parameterized constructor
What is destructor
What is Polymorphism
What is Polymorphism types
What is overloading
What is overriding
What is abstraction
What is abstract class
Implementation of abstract method
What is interface
What is difference between abstract class and interface
What is inheritance
Inheritance types
What is single inheritance
What is multiple inheritance
What is multilevel inheritance
How to use static method and property in inheritance
How to use self and parent with static
How to use self and parent without static
What is visibility
What is the difference between public, private, and protected
What is final
What is final class

Copyright ©2022 coderraj.com. All Rights Reserved.