Is it possible to create more than one constructor in a class like in Java.
😕
(Constructors are functions of a class with the same name as the class. These functions are run when an object of the class is initialised)
Example:
class text
{
var $text;
function text() //default constructor
{
}
function text($value) //contructor
{
$this->text = $value;
}
function getText() //return function
{
return $this->text;
}
}
The difference between the two contructors is only the number of attributes. Using more than one contructor makes it possible to initialise an object in more than one way:
$text1 = new text;
$text2 = new text("hello");
where $text1->getText(); would echo "" and $text2->getText(); "hello"
:p
Tnx