Saturday, April 29, 2017

call_user_func

<?php
 $e = "n * 2";
 function incr($expression) {
  $expression = str_replace('n', '$n', $expression);  
  
  $func_body = "
   \$increment = (int)($expression + 1);
   return \$increment;";
  return create_function('$n', $func_body);
 }
 $increment_func = incr($e);
 echo call_user_func($increment_func, 2);
?>
Output:
5

No comments:

Post a Comment

here docs

$x = <<<THE_END PHP stands for "PHP: Hypertext Preprocessor". The acronym "PHP" is therefore, usually referre...