I just have found out that there is a function called func_get_arg
in PHP which enables developer to use variant style of getting arguments.
It seems to be very us
I hardly ever use func_get_arg()
, but I do use its cousin func_get_args()
quite a bit. Here's one example, a function along the lines of the echo
statement that entity encodes all its arguments:
function ee() {
$args = func_get_args();
echo implode('', array_map('htmlentities', $args));
}
I use that function quite a bit.
Here's another useful example, a function that does the same job as SQL's COALESCE()
function.
function coalesce() {
$args = func_get_args();
foreach ($args as $arg) {
if (!is_null($arg)) {
return $arg;
}
}
return null;
}
It returns the first non-null argument passed in, or null
if there's no such argument.