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

Answers were Sorted based on User's Feedback



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

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

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

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

Post New Answer

More PHP Interview Questions

How many php functions are there?

1 Answers  


Explain different sorting function in php?

1 Answers  


Php code to find whether a number armstrong or not?

1 Answers  


What is php call function?

1 Answers  


What type of comments are supported by PHP.

1 Answers  


What is the use of $_server["php_self"] variable?

1 Answers  


Explain scalar type declarations in php7?

1 Answers  


Is php a web server?

1 Answers  


is php is the best for this situation

2 Answers  


What is artisan in php?

1 Answers  


What does mvc stand for and what does each component do?

1 Answers  


Explain the ternary conditional operator in php?

1 Answers  


Categories