what is constructor in a class, how it is work, how it is call?

Answer Posted / kapil dhiman

Constructor is a special function which is automaticaly called when object of the class is created.In php4 costructor having the same name of the class while in php5 costructor function declare like __construct(){ }.
<?
class MakeConstruct{

public function __construct(){

echo "php5 construct";

}


public function MakeConstruct(){

echo "php4 construct";

}

}

$obj= new MakeConstruct();

?>

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do I run php?

729


How to get the number of characters in a string?

799


Write a program to find no of days between two dates in php?

731


How we can get the number of elements in an array?

8614


Do you know what is the differences between $a != $B and $a !== $B?

726


How will you calculate days between two dates in PHP?

810


Why are sessions used?

731


Name some of the constants in php and their purpose.

746


How to retrieve the original query string?

793


What is the different between count() and sizeof() in php?

731


How to initiate a session in php?

894


Tell me are parent constructors called implicitly inside a class constructor?

752


What are getters and setters and why are they important?

772


What is php.ini & .htacess file?

773


What are php expressions?

827