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 to close a session properly?

528


How to get ip address of clients machine?

560


Explain what are the two main string operators?

517


What is the difference between static and dynamic websites?

507


Is php harder than javascript?

428






How can we increase execution time of a php script?

491


How to open a file in php?

618


How to update memcached when you make changes to php?

538


Tell us how can we access the data sent through the url with the post method?

520


What is the purpose of break and continue statement?

525


What are php loops?

535


What is difference between base_url and site_url?

498


What is the use session in php?

548


Is null function in php?

570


How do I repair phpmyadmin?

518