note 53761 added to function.eval
| From: | dale at mlmservices dot co dot uk | Date: | Sun, 12 Jun 2005 12:41:18 +0000 |
| Subject: | note 53761 added to function.eval | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-90299@lists.php.net to get a copy of this message | ||
I had a requirement to pull in parameters from a database as well as the code needed to run. What
to do, what to do. So I created a function that calls eval() twice - once to insert the params and
once to run the code with the params inserted. Here it is for readability.
<?php
$args[0] = '400';
$args[1] = '200';
$func_code = "return max($args[0], $args[1]);"; // Note "return" keyword must
be used
echo testeval($args, $func_code);
function testeval($args, $func_code) {
eval($str = $func_code); // Insert params into code
return eval($str); // execute code
}
?>
I hope this helps somebody :)
----
Manual Page -- http://www.php.net/manual/en/function.eval.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+53761
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+53761&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+53761&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+53761&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+53761&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+53761&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+53761&report=yes
Search -- http://master.php.net/manage/user-notes.php