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 开发者_如何学JAVAare 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.
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)
{...
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.
The documentation on the filter_input
method suggests that the expected value is an integer so it would probably be 0
.
精彩评论