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 — Bir COM bileşeninin yöntemini çalıştırır [terk edilmiştir]
Tanımı
com_invoke() işlevi, comNesnesi
ile gönderimi tanımlanan COM bileşeninin yontemAdi
yöntemini çağırır. com_invoke() işlevi hata durumunda
FALSE döner, başarı durumunda yontemAdi değerini
döner. yontemDegistirgeleri ile verilenler
yontemAdi ile adı verilen yönteme geçirilir.
Örnek 1 com_invoke() yerine nesneye yönelik sözdizimi kullanın
<?php
// bu şekilde çağırmak yerine
$val = com_invoke($obj, 'method', $one, $two);
// bu şekilde çağırın
$val = $obj->method($one, $two);
?>
Bilginize: Bu işlev PHP 5'te yoktur. Yöntemleri çağırmak ve özelliklere erişmek için bu işlevin yerine normal ve daha doğal olan nesne yönelimli söz dizimini kullanmalısınız.
tomer at parity-bit dot com ¶
8 years ago
