note 66288 added to language.oop5.decon
| From: | PeterMolnar at osu1 dot php dot net | Date: | Thu, 18 May 2006 13:24:45 +0000 |
| Subject: | note 66288 added to language.oop5.decon | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-111591@lists.php.net to get a copy of this message | ||
There were many notes about the inability of defining multiple constructors for the class.
My solution is to define separate static methods for each type of constructor.
<?php
class Vector {
private $x;
private $y;
public function __construct() {
$this->x = 0;
$this->y = 0;
}
public static function createXY($x, $y) {
$v = new Vector();
$v->x = $x;
$v->y = $y;
return $v;
}
}
?>
----
Server IP: 66.163.161.117
Probable Submitter: 213.134.24.88
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/language.oop5.decon.php
Edit -- http://master.php.net/note/edit/66288
Del: integrated -- http://master.php.net/note/delete/66288/integrated
Del: useless -- http://master.php.net/note/delete/66288/useless
Del: bad code -- http://master.php.net/note/delete/66288/bad+code
Del: spam -- http://master.php.net/note/delete/66288/spam
Del: non-english -- http://master.php.net/note/delete/66288/non-english
Del: in docs -- http://master.php.net/note/delete/66288/in+docs
Del: other reasons-- http://master.php.net/note/delete/66288
Reject -- http://master.php.net/note/reject/66288
Search -- http://master.php.net/manage/user-notes.php