note 49568 added to function.com-invoke

From: Date: Tue, 01 Feb 2005 20:21:19 +0000
Subject: note 49568 added to function.com-invoke
Groups: php.notes 
Request: Send a blank email to php-notes+get-84344@lists.php.net to get a copy of this message
Note that if you want to use a string to specify the method to call (e.g. a drop-down list to decide what to do to a server process) you can do this in three ways. The first is to use this function, as in <?php com_invoke($obj, $_GET['func']); ?> That's bad. The second is to use eval(), as in <?php eval("\$obj->{$_GET['func']}();"); ?> That's very very very *very* bad. The third is to use call_user_func(), as in <?php call_user_func(array($obj, $_GET['func'])); ?> That's very good. Remember to validate the user input against a list of allowed methods if a non-admin is at the console. http://php.net/manual/en/function.call-user-func.php ---- Manual Page -- http://www.php.net/manual/en/function.com-invoke.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+49568 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49568&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49568&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49568&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49568&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49568&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+49568&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#84344) next »