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 — Appelle une méthode d'un composant (déconseillé)
Description
com_invoke() appelle la méthode function_name du composant COM com_object . com_invoke() retourne FALSE en cas d'erreur, sinon retourne le résultat de la fonction function_name en cas de succès. Tous les paramètres supplémentaires function_parameters sont passés à la méthode function_name .
Exemple #1 N'utilisez pas com_invoke(), utilisez la syntaxe OO à la place
<?php
// do this
$val = $obj->method($one, $two);
// instead of this:
$val = com_invoke($obj, 'method', $one, $two);
?>
Note: Cette fonction n'existe pas en PHP 5 ; à la place, vous devriez utiliser la syntaxe OO pour accéder aux propriétés ou appeler les méthodes.
com_invoke
tomer at parity-bit dot com
01-Feb-2005 08:21
01-Feb-2005 08:21
