Forum Moderators: coopster

Message Too Old, No Replies

Optional function arguments?

         

aspr1n

10:30 am on May 13, 2003 (gmt 0)

10+ Year Member



I have a function with two arguments, defined as:

function name( $var1, $var2 ) { 
stuff...
}

How can I make at least one of the two arguments optional to supress the "Warning: Missing argument 2" error message?

Cheers,

asp

ruserious

10:51 am on May 13, 2003 (gmt 0)

10+ Year Member



You can give it a default value:

function name( $var1, $var2=NULL ) 
{ stuff... }

aspr1n

11:29 am on May 13, 2003 (gmt 0)

10+ Year Member



he he didn't think to try this in PHP!

Cheers,

cidrolin

11:01 am on May 15, 2003 (gmt 0)

10+ Year Member



I believe prefixing the function call with "@" character will prevent warning output; it's also possible to modify php error-reporting level using the error_reporting() php function .

BCMG_Scott

6:48 pm on May 15, 2003 (gmt 0)

10+ Year Member



Another idea is to use the func_get_args() and func_num_args() functions.

Scott Geiger