note 26636 added to language.oop

From: Date: Thu, 07 Nov 2002 21:26:05 +0000
Subject: note 26636 added to language.oop
Groups: php.notes 
Request: Send a blank email to php-notes+get-39101@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" -- http://www.php.net/manual/en/language.oop.php http://master.php.net/manage/user-notes.php?action=edit+26636 http://master.php.net/manage/user-notes.php?action=delete+26636 http://master.php.net/manage/user-notes.php?action=reject+26636

« previous php.notes (#39101) next »