Constructor:-
* 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.
Example:-
class A {
function A(){
echo "User Defined Constructor";
}
__construct(){
echo "Predefined Defined Constructor";
}
}
$obj=new A();
Output:-
Predefined Defined Constructor
Copyright ©2022 coderraj.com. All Rights Reserved.