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

What is get method in java?

721


How to block direct directory access in PHP?

725


Where do I run php code?

706


How do you trim spaces in excel?

754


What is the use of limit in mysql?

711


What is mvc php?

700


What is a http session?

720


How does session work in php?

739


How to convert a string to uppercase in php?

724


What does $_server mean?

741


What is the use of $_request variable?

782


What is strcmp () in php?

717


What is the use of rand() in php?

791


What does addslashes do in php?

729


How to increase the execution time of a PHP script?

726