Re: Classes Constructor syntax

From: Date: Thu, 18 Jul 2002 00:12:15 +0000
Subject: Re: Classes Constructor syntax
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-108081@lists.php.net to get a copy of this message
I'm no guru, but here goes anyway ... default variable values can simply be set with a "var" statement: var $somevar1 = "value1"; var $somevar2 = "value2"; or with a "set" function: var $somevar1; var $somevar2; function setsomevar1() { $this->somevar1 = "value1"; } function setsomevar2() { $this->somevar2 = "value2"; } One "set" function could probably query a database and set all your vars in one go: function setallvars() { // query db, get values $this->somevar1 = "value1"; $this->somevar2 = "value2"; } Amyway, you could then call the set var functions from within your constructor: function issue() { setallvars(); or setsomevar1(); setsomevar2(); } Just a suggestion. No doubt someone will correct me if I'm wrong ... I'm new to OOP myself. 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 > > > -- -------------------------------- n i n t i . c o m php-python-perl-mysql-postgresql -------------------------------- Michael Hall ninti@ninti.com --------------------------------

« previous php.general (#108081) next »