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 — Llama a un método de un componente COM [obsoleto]
Descripción
com_invoke() invoca el método llamado function_name del componente COM referebciado por com_object. com_invoke() devuelve FALSE en caso de error, devuelve el valor devuelto por function_name en caso de éxito. Todos los parámetro extra function_parameters son pasados al método function_name.
Example #1 No use com_invoke(), en su lugar usar la sintaxis OO
<?php
// haga esto
$val = $obj->método($uno, $dos);
// en lugar de esto:
$val = com_invoke($obj, 'método', $uno, $dos);
?>
Note: This function does not exist in PHP 5; instead, you should use the regular and more natural OO syntax to access properties or call methods.
tomer at parity-bit dot com
01-Feb-2005 08:21
