Re: default and another constructor

From: Date: Wed, 12 May 2004 13:27:19 +0000
Subject: Re: default and another constructor
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-185985@lists.php.net to get a copy of this message
On Wed, 2004-05-12 at 15:18, Mark Constable wrote: > On Wed, 12 May 2004 10:43 pm, Lieve Vissenaeken wrote: > > Please ,could anybody help me ? I'm not so familiar with PHP. > > > > I've the following problem with my code when I try to make an object from > > the class "forum" with the code "$test=new forum()". I always get a > > warning on this: "Warning: Missing argument 1 for forum() in > > /lvdata/www/tennis/php/sql.inc" > > Is it not possible to just make a default constructor and an other > > constructor like in JAVA ? > > Thanks for helping.... > > No, you cannot do this kind of method overloading, not like > this anyway. If you are using PHP5 you can kind of emulate > overloading by using the __call() function... some googling > will find examples. > > You can at least make the below work by removing the first > forum() instance and using > > function forum($naam=NULL,$tijd=NULL,$tekst=NULL) > > and test the incoming variables with isset() before attempting > to use any of them. If you assign default values to the method arguments, you cannot test them with isset() anymore, as they will be set. > > > class forum > > { > > var $naam; > > var $tijd; > > var $tekst; > > > > function forum() > > { > > } > > > > function forum($naam,$tijd,$tekst) > > { > > $this->naam=$naam; > > $this->tijd=$tijd; > > $this->tekst=$tekst; > > } > > } > > > > > > $test=new forum(); > > --markc

Attachment: [application/pgp-signature] This is a digitally signed message part signature.asc
« previous php.general (#185985) next »