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

Is php dying 2018?

0 Answers  


Does it possible to compile php with mysql without having mysql sources?

2 Answers  


What is php sequence?

0 Answers  


How to remove an empty directory?

0 Answers  


Is it possible to use com component in php?

0 Answers  


Inside a php function, what param needs to be set in order to access a global variable?

0 Answers  


What are the new features in php 7?

0 Answers  


i am a php programmer can i be a java programmer?

3 Answers  


Tell me how can we automatically escape incoming data?

0 Answers  


client side scripting language Vs server side scripting language

7 Answers   IBM, IRT,


What is difference between single quotes and double quotes in php?

0 Answers  


Tell me is it possible to remove the html tags from data?

0 Answers  


Categories