Re: Custom function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 16 February 2011 21:00, Dan Schaefer <dan@xxxxxxxxxxxxxxxxxxxx> wrote:
> In my code, I set the optional parameter to NULL and check for triple equals
> "===" or "!==" to see if the variable has been passed with a value. IMO,
> this is the safest way.
>
> function MyFunction($x, $y, $z=NULL) {
> if ($z !== NULL) {
> // Do Something
> }
> }

In case you're actually trying to test if a variable was passed or not
that doesn't work (as it doesn't detect NULL passed in). Use
func_get_args() as that gives you any and all arguments passed to the
function, excluding defaults.

That said, if you're making use of optional parameters and need to
check if anything was passed in, you're almost certainly doing things
wrong.

Regards
Peter

-- 
<hype>
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
</hype>

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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux