douzhantao2857 2017-04-20 19:01
浏览 29

从HHVM C ++扩展运行PHP函数

Is it possible? Without using Zend API, only Native. For use it like in PHP extension:

call_user_function(EG(function_table), NULL, &func, &retval, 1, params);
  • 写回答

1条回答 默认 最新

  • dongpeng7744 2017-04-21 17:52
    关注

    You most likely want vm_call_user_func().

    Variant vm_call_user_func(const Variant& function, const Variant& params,
                              bool forwarding = false);
    

    Depending on what your extension is doing at the time of the call, you likely will want to catch exceptions the function may throw.

    try {
      vm_call_user_func(function, params);
    } catch (const Object&) {
      try {
        raise_warning("got exception in my extension");
      } catch (const Object&) {
        // exception in error handler!
      }
    }
    

    vm_call_user_func knows how to handle the various ways PHP defines callables (e.g. "SomeClass::someMethod", array($obj, "method")).

    Depending on how the function to call is being provided, there may be more optimal ways. You could require that instead of any arbitrary callback, the user must provide a closure object. Since a closure object is always callable (i.e. you don't have to validate that SomeClass exists in my "SomeClass::someMethod" example), you can extract the underlying object, store it instead of the Variant and vm_call_user_func() will save some overhead decoding and validating it.

    评论

报告相同问题?

悬赏问题

  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示