0

So, I know that with PHP you can define optional parameters (StackOverflow Questions).

What I'm trying to do is the following:

function myFunc($a, $b, $c, $type, $variable_name, $filter, $options)
{
   $value = filter_input($type, $variable_name, $filter, $options);

   //Do something with $a, $b, $c, and $value
}

Since I am passing in parameters that pertain to the built in function of filter_input I know that $filter and $options are optional parameters, and to make them optional I would simply assign them a default value. But, I'm not sure what that default value should be. My guess is that $filter should default to FILTER_DEFAULT, which makes sense, but I can not find any information as to what $options should default to.

Community
  • 1
  • 1
michael
  • 14,844
  • 28
  • 89
  • 177

3 Answers3

2

Default both $filter and $options to NULL. They are optional for filter_input() as well, so why assign them a value when filter_input() will do it for you? If PHP were ever to update the defaults for the function then you'd still be current, too.

Your function would look like this:

function myFunc($a, $b, $c, $type, $variable_name, $filter=NULL, $options=NULL)
{...
Surreal Dreams
  • 26,055
  • 3
  • 46
  • 61
  • So if I do filter_input($type, $variable_name, null, null) that will be the same as filter_input($type, $variable_name) ? – michael Dec 21 '10 at 14:46
  • That's exactly equivalent. You either spell out the NULL values or you imply them, but either way you pass NULL. – Surreal Dreams Dec 21 '10 at 15:15
0

The documentation on the filter_input method suggests that the expected value is an integer so it would probably be 0.

random
  • 9,774
  • 10
  • 66
  • 83
Matt Asbury
  • 5,644
  • 2
  • 21
  • 29
0

As the options argument for the filter_input function is er.. optional and can be either an array or a bitmask, so I suspect using...

function myFunc($a, $b, $c, $type, $variable_name, $filter, $options=null) {
    ...

..would be ideal, unless there's an application specific reason for doing otherwise.

John Parker
  • 54,048
  • 11
  • 129
  • 129