View Single Post

  #3 (permalink)  
Old 11-16-2004
Pedro Graca
 
Posts: n/a
Default Re: Default parameter

Mike wrote:
> If possible, how do I use a function to create a default parameter
> value?
>
> The following gives me an "unexpected '(', expecting ')'"
> error, which makes sense.
>
> function DisplayInfo($ID, $startdate=date("Ydm"), $numdays=7) {
> ...function here...
> }



The default value has to be a constant. It cannot be a variable or a
class member or (as you noticed) a function call.


function DisplayInfo($ID, $startdate=NULL, $numdays=7) {
if (is_null($startdate)) $startdate = date('Ydm');
...function here...
}


--
Mail sent to my "From:" address is publicly readable at http://www.dodgeit.com/
== ** ## !! !! ## ** ==
TEXT-ONLY mail to the complete "Reply-To:" address ("My Name" <my@address>) may
bypass the spam filter. I will answer all pertinent mails from a valid address.
Reply With Quote