Re: default and another constructor
| From: | Lieve Vissenaeken | Date: | Wed, 12 May 2004 13:43:07 +0000 |
| Subject: | Re: default and another constructor | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-185989@lists.php.net to get a copy of this message | ||
Thanks Mark for helping me out...
The way you describe it with "function
forum($naam=NULL,$tijd=NULL,$tekst=NULL)" is a good trick !!
Kind Regards.
"Mark Constable" <markc@renta.net> schreef in bericht
news:200405122318.43873.markc@renta.net...
> 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.
>
> > 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