怎样用c++实现php的call_user_func

解决方案 »

  1.   

    call_user_func是什么啊,回调函数么?
    能在详细一点说明么?
      

  2.   

     call_user_func
    (PHP 3>= 3.0.3, PHP 4 , PHP 5)call_user_func --  Call a user function given by the first parameter 
    Description
    mixed call_user_func ( callback function [, mixed parameter [, mixed ...]])
    Call a user defined function given by the function parameter. Take the following: <?php
    function barber($type) 
    {
        echo "You wanted a $type haircut, no problem";
    }
    call_user_func('barber', "mushroom");
    call_user_func('barber', "shave");
    ?>  Object methods may also be invoked statically using this function by passing array($objectname, $methodname) to the function parameter. <?php
    class myclass {
      function say_hello() 
      {
        echo "Hello!\n";
      }
    }$classname = "myclass";call_user_func(array($classname, 'say_hello'));
    ?>  
     
    就是一个通过字符串执行与这个字符串同名的函数的函数!
      

  3.   

    我是在数据库中存放了该函数的同名字符串。
    在数据库中取出来的只是字符串,不能得到对应函数的指针只需要传一个与函数名相同的字符串就能call这个函数了。有点像dll中的 GetProcAddress难道只能把所有有可能调用的函数都封装在dll里面?
      

  4.   

    编译成二进制代码后无所谓函数名称的问题,只需要地址就可以了。
    当然,导出函数除外,在导出表中有函数名的记录。你可以把你要调用的函数都弄成导出函数,然后在程序里面用GetProcAddress
      

  5.   

    顶一顶,我的意思是通过字符串执行函数。就像php中的
    call_user_func那样
    <?php 
    function barber($type) 

        echo "You wanted a $type haircut, no problem"; 

    call_user_func('barber', "mushroom"); 
    call_user_func('barber', "shave"); 
    ?>
    这里的结果是:
    You wanted a mushroom haircut, no problem
    You wanted a shave haircut, no problem
      

  6.   

    这个不会PHP,简单点,需要对函数名做映射处理吧,不就是需要swtich case这样的逻辑吗?与其这样,还不如直接调用?
      

  7.   

    难道是要调用脚本函数,类似lua/python等???使用脚本引擎?
      

  8.   

    不管使用dll还是com,都需要导出函数名称才可以用名称来动态调用函数;否则程序中根本没有这个名字啊。也可以用脚本解决。