<?php
$e = "n * 2";
function incr($expression) {
$expression = str_replace('n', '$n', $expression);
$func_body = "
\$increment = (int)($expression + 1);
return \$increment;";
echo("Func body: " . $func_body);
return create_function('$n', $func_body);
}
$increment_func = incr($e);
echo $increment_func(2) . "<br/>";
?>
Output:
Func body: $increment = (int)($n * 2 + 1); return $increment; 5
No comments:
Post a Comment