RE: [PHP] Re: blank function parameters

From: Date: Wed, 03 Nov 2004 19:24:19 +0000
Subject: RE: [PHP] Re: blank function parameters
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-201077@lists.php.net to get a copy of this message
Thanks for all the help guys, working great now. Giles Roadnight http://giles.roadnight.name -----Original Message----- From: Daniel Schierbeck [mailto:dasch@ulmail.net] Sent: 03 November 2004 18:37 To: php-general@lists.php.net Subject: [PHP] Re: blank function parameters Matthew Weier O'Phinney wrote: > * Daniel Schierbeck <dasch@ulmail.net>: > >>Giles Roadnight wrote: >> >>>If I defined a function with 4 parameters but only pass 3 I get an >>>error. Is there anyway around this? >>> >>>I want to be able to set the missing parameter to a default value if it >>>is not passed which works ok but How do I get rid of the error message? >> >>If you want an argument to be optional and still be able to check >>whether or not it's been set, you can use NULL as the default value: >> >>function foobar ($a, $b, $c = null) >>{ >> if (isset($c)) { >> echo 'The third argument was set'; >> } >>} > > > That check should be for 'is_null($c)' as the default value of $c will > be null, and it will be always set, even if not sent. > > isset(null) evaluates to false... -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/register&r=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#201077) next »