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

Explain the difference between array_merge() and array_combine()?

0 Answers  


How to implement a class named dragonball. This class must have an attribute named ballcount (which starts from 0) and a method ifoundaball. When ifoundaball is called, ballcount is increased by one. If the value of ballcount is equal to seven, then the message you can ask your wish is printed, and ballcount is reset to 0. How would you implement this class?

0 Answers  


what use of <?php

1 Answers   CBS,


What is difference between get and post?

0 Answers  


if you run the app program all vendor open items are cleared but is it possible to reverse the again again open items please tell me the answer

0 Answers   Yash Technologies,






What is php explain?

0 Answers  


What are the limitations or drawbacks of PHP ?

4 Answers   iDream,


What are the advantages of php mysql?

0 Answers  


Difference between get and post method.

0 Answers  


How to submit form without a submit button.

0 Answers  


How to convert strings in hex format?

0 Answers  


Hi, My Name is Ajay Jha. What My Question is I am Percuing in Bca. It's My 5th Semester. I Want To Make My Carrear as a web designer that's Why i wants to do Php, Is it right Desision for Me ?

1 Answers  


Categories