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
com_invoke
(PHP 4)
com_invoke — COM コンポーネントのメソッドをコールする [非推奨]
説明
com_invoke() は、 com_object が指す COM コンポーネントの メソッド function_name をコールします。 com_invoke() はエラーの場合に FALSE を返し、 成功時に function_name の返り値を返します。 追加パラメータ function_parameters の値が メソッド function_name に渡されます。
例1 com_invoke() を使用せず、かわりにオブジェクト指向の構文を使用する
<?php
// こちらを使用します
$val = $obj->method($one, $two);
// こちらは推奨しません
$val = com_invoke($obj, 'method', $one, $two);
?>
注意: この関数は PHP 5 には存在しません。 より自然なオブジェクト指向形式の構文で、 プロパティにアクセスしたりメソッドをコールしたりすることになります。
com_invoke
tomer at parity-bit dot com
02-Feb-2005 05:21
02-Feb-2005 05:21