Re: Classes Constructor syntax

From: Date: Thu, 01 Jan 1970 00:00:00 +0000
Subject: Re: Classes Constructor syntax
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-108172@lists.php.net to get a copy of this message
++>PHP does not support multiple constructors. but you can easily evade this obstacle: class A { function A($parm1,$parm2=false) { if (!$parm2) { $this->OneArgConstructor($parm1); } else { $this->TwoArgConstructor($parm2); } } function OneArgContructior($parm) { //... } function TwoArgConstructior($parm1,$parm2) { //... } } Rados ++> ++>Michael ++> ++>On Wed, 17 Jul 2002, David Russell wrote: ++> ++>> Hi all, ++>> ++>> I am finally spending some time converting a million and one functions ++>> into a class - this is for a software issue tracking system. ++>> ++>> I have: ++>> ++>> class issue { ++>> var ++>> var ++>> ... ++>> ++>> function issue() { //default constructor ++>> //initialise all variables to defaults, and start getting the stuff ++>> from forms ++>> } ++>> ++>> function issue($number) { //1 variable constructor ++>> // Query database and populate variables accordingly ++>> } ++>> } ++>> ++>> My question is: will this work? does PHP OOP support more than one ++>> constructor? If my syntax is wrong, please let me know the correct syntax. ++>> ++>> Thanks ++>> ++>> David R ++>> ++>> ++>> ++> ++> -- -- pozdr Rad0s Radek Gajewski rgajew@sgh.waw.pl GG:694459 ICQ:110153822 --------------------------------------------------------

« previous php.general (#108172) next »