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

What is $_ request in php?

0 Answers  


In PHP how many size data can upload by default?

9 Answers   Classic Infotech, PG Software,


Are react hooks stable?

0 Answers  


What is the difference between php and cakephp?

0 Answers  


How we load all classes that placed in different directory in one php file , means how to do auto load classes.

0 Answers  






What are the different functions in sorting an array?

2 Answers  


How to join multiple strings into a single string?

0 Answers  


What is cURL in PHP?

0 Answers  


What is isset post?

0 Answers  


how can i get USA time using php...

1 Answers  


What is the use of the function htmlentities?

0 Answers  


How to send Email using PHP with MySQL in Linux Server?..

3 Answers  


Categories