note 26636 rejected from language.oop by maxim
| From: | maxim@php.net | Date: | Fri, 08 Nov 2002 11:36:25 +0000 |
| Subject: | note 26636 rejected from language.oop by maxim | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-39152@lists.php.net to get a copy of this message | ||
Is it possible to create more than one constructor like in Java.
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"