note 59338 added to function.eval
| From: | djogopatrao at gmail dot com | Date: | Sat, 03 Dec 2005 16:14:35 +0000 |
| Subject: | note 59338 added to function.eval | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-99522@lists.php.net to get a copy of this message | ||
As a matter of fact, you don't need to use eval() if you want to call a function whose name is
in some variable, say $function. You just need to call $function(...);
An obvious example (with some interesting implications):
<?
$repository = new Repository();
$function = $_REQUEST[operation];
echo $repository->$function( $_REQUEST[id] );
?>
One must put all functions that can be called at the class Repository. It's not a good idea to
do
<? $_REQUEST[operation]() ?>
or the user can run anything he wants to (my own experience here) =)
----
Manual Page -- http://www.php.net/manual/en/function.eval.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+59338
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+59338&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+59338&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+59338&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+59338&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+59338&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+59338&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+59338&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+59338&report=yes
Search -- http://master.php.net/manage/user-notes.php