Just for the hell of it, and of little or no use otherwise:
function my_function()
{
$num_vars = 0;
$num_cons = 0;
$args = func_get_args();
$var = '';
for ($i = 0; $i < (count($args) - 2); $i++) {
if (in_array($args[$i], $args[count($args) - 2])) {
$num_vars++;
echo 'Variable: ' . $args[$i] . '<br />';
} elseif (in_array($args[$i], $args[count($args) - 1])) {
$num_cons++;
echo 'Constant/literal: ' . $args[$i] . '<br />';
}
$var .= $args[$i];
}
$ret[0] = $var;
$ret[1] = $num_vars;
$ret[2] = $num_cons;
return $ret;
}
$a = 'Hello';
$b = 'world';
define('C', '!');
$def_vars = get_defined_vars();
$def_cons = get_defined_constants();
$arr = my_function($a, ', ', $b, C, $def_vars, $def_cons);
echo 'String: ' . $arr[0] . '<br />';
echo 'String constructed with ' . $arr[1] . ' variables and ' . $arr[2] . ' constants/literals.';
Variable: Hello
Constant/literal: ,
Variable: world
Constant/literal: !
String: Hello, world!
String constructed with 2 variables and 2 constants/literals.
But how does ", " get into $def_cons?