what is constructor in a class, how it is work, how it is call?
Answers were Sorted based on User's Feedback
Answer / sei thu htun
Constructors are functions in a class that are automatically
called when you create a new instance of a class with new. A
function becomes a constructor, when it has the same name as
the class. If a class has no constructor, the constructor of
the base class is being called, if it exists.
| Is This Answer Correct ? | 5 Yes | 1 No |
Answer / 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 |
Who is the father of PHP and explain the changes in PHP versions?
13 Answers Befree, iMark Group, Netizen,
Do you know what are traits?
What software is required for php?
Write a select query that will be displayed the duplicated site name and how many times it is duplicated?
Tell me how can we change the maximum size of the files to be uploaded?
Can php run without server?
What is a controller php?
What is difference between echo and print in php?
How to create a text file in PHP?
Tell me how a constant is defined in a php script?
How is traits used in php?
Define urlencode() and urldecode() used in php?