So I know that you can code for a function's arguments to have a default value if it is not supplied when the function is called like this:
I added an example of how the interface could be implemented:
interface my_interface {
function my_function();
}
class my_class implements my_interface {
# because the interface calls for a function with no options an error would occur
function my_function($arg_one, $arg_two = 'name') {
...
}
}
class another_class implements my_interface {
# this class would have no errors and complies to the implemented interface
# it also can have any number of arguments passed to it
function my_function() {
list($arg_one, $arg_two, $arg_three) = func_get_args();
...
}
}
However, I like making my functions invoke the func_get_args() method instead so that when using them inside classes I can implement functions from an interface. Is there a way to use the list() function so that I can assign variables a default value or do I need to do it the verbose and ugly way? What I have right now is:
function my_function() {
list($arg_one, $arg_two) = func_get_args();
if(is_null($arg_two)) $arg_two = 'name';
...
}
What I would like, is something that accomplishes the same thing, but isn't so verbose. Maybe something like this, but of course doesn't flag an error:
function my_function() {
# If $arg_two is not supplied would its default value remain unchanged?
# Thus, would calling the next commented line would be my solution?
# $arg_two = 'name';
list($arg_one, $arg_two = 'name') = func_get_args();
...
}