RE: [PHP] default and another constructor

2004-05-12 Thread Ford, Mike [LSS]
> -Original Message-
> From: Rudy Metzger [mailto:[EMAIL PROTECTED] 
> Sent: 12 May 2004 14:27
> 
> On Wed, 2004-05-12 at 15:18, Mark Constable wrote:
> > 
> >  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.

Not if the default is NULL -- isset(NULL) is false.

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services, JG125, James Graham 
Building, Leeds Metropolitan University, Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] default and another constructor

2004-05-12 Thread Michal Migurski
> 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)

Another option, if you wish to have varying argument lists, is to define
the methods with no arguments at all, and use the func_get_args(),
func_num_args(), and func_get_arg() functions described here:

http://php.net/manual/en/ref.funchand.php

-
michal migurski- contact info and pgp key:
sf/cahttp://mike.teczno.com/contact.html

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] default and another constructor

2004-05-12 Thread Mark Constable
On Wed, 12 May 2004 11:27 pm, Rudy Metzger wrote:
> On Wed, 2004-05-12 at 15:18, Mark Constable wrote:
> > 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.

# cat null_test.php

# php null_test.php
'hi'
NULL
NULL

--markc

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] default and another constructor

2004-05-12 Thread Lieve Vissenaeken
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" <[EMAIL PROTECTED]> schreef in bericht
news:[EMAIL PROTECTED]
> 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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] default and another constructor

2004-05-12 Thread Rudy Metzger
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


signature.asc
Description: This is a digitally signed message part


Re: [PHP] default and another constructor

2004-05-12 Thread Rudy Metzger
Strange that you get this error. Normally you should get a "Fatal error:
Cannot redeclare forum::forum() "

PHP does not support 'function overloading', at least not in a way java
is doing it. One of the drawbacks of a free typed langauge (in contrary
to a strictly typed one).

cheerio
/rudy

On Wed, 2004-05-12 at 14:43, 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
> 
> 
> 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();


signature.asc
Description: This is a digitally signed message part


Re: [PHP] default and another constructor

2004-05-12 Thread Mark Constable
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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] default and another constructor

2004-05-12 Thread Lieve Vissenaeken
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


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();

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php