[PHP] Re: blank function parameters
* Giles Roadnight [EMAIL PROTECTED]: 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? Read about functions on php.net. Basically, yes: function someFunc($arg1, $arg2, $arg3, $arg4 = 'default') {} -- Matthew Weier O'Phinney | mailto:[EMAIL PROTECTED] Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: blank function parameters
Giles Roadnight wrote: Hello 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? Thanks Giles Roadnight http://giles.roadnight.name It's in the manual. function foo($aaa, $bbb, $ccc, $ddd=) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: blank function parameters
Giles Roadnight wrote: Hello 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? Thanks Giles Roadnight http://giles.roadnight.name 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'; } } -- Daniel Schierbeck Help spread Firefox (www.getfirefox.com): http://www.spreadfirefox.com/?q=user/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: blank function parameters
* Daniel Schierbeck [EMAIL PROTECTED]: 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. -- Matthew Weier O'Phinney | mailto:[EMAIL PROTECTED] Webmaster and IT Specialist | http://www.garden.org National Gardening Association| http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: blank function parameters
To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm On 03 November 2004 16:39, Matthew Weier O'Phinney wrote: * Daniel Schierbeck [EMAIL PROTECTED]: 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. Nope. At least not necessarily. isset(NULL) returns true, so the test as originally written is valid. However, it may be that you want to handle the no-value-supplied case first, in which case: if (is_null($c)): /// handle default case else: ... endif; might be slightly more legible than if (!isset($c)): etc. Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Headingley Campus, 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
[PHP] Re: blank function parameters
Matthew Weier O'Phinney wrote: * Daniel Schierbeck [EMAIL PROTECTED]: 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/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: blank function parameters
Thanks for all the help guys, working great now. Giles Roadnight http://giles.roadnight.name -Original Message- From: Daniel Schierbeck [mailto:[EMAIL PROTECTED] Sent: 03 November 2004 18:37 To: [EMAIL PROTECTED] Subject: [PHP] Re: blank function parameters Matthew Weier O'Phinney wrote: * Daniel Schierbeck [EMAIL PROTECTED]: 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/registerr=6584 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: blank function parameters
On 3 Nov 2004 16:38:39 -, Matthew Weier O'Phinney [EMAIL PROTECTED] wrote: * Daniel Schierbeck [EMAIL PROTECTED]: 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. The example above is correct ... you can check with isset($c) and always will return false, as the manual says: isset() will return FALSE if testing a variable that has been set to NULL. Regards, Jordi. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php