Function arguments to not uniquely identify a function. In Java the arguments are strictly defined. This allows the compiler to know which function you are calling.
But, in PHP this is not the case.
function a()
{
$args = func_get_args();
foreach($args as $value)
{
echo $value;
}
}
It's possible to create function that has no arguments define, but still pass it arguments.
a("hello","world")
would output
hello world
As a result, PHP can't tell the different between a() and a($arg). Therefore, a() is already defined.
PHP programmers have different practices to handle this single function problem.
You can define an argument with default values.
a($arg = 'hello world');
You can pass mixed variable types.
function a($mixed)
{
if(is_bool($mixed))
{
.....
}
if(is_string($mixed))
{
.....
}
}
My preference is to use arrays with defaults. It's a lot more flexible.
function a($options=array())
{
$default = array('setting'=>true);
$options = array_merge($default,$options);
....
}
a(array('setting'=>false);