douhuan1979 2018-09-11 04:35 采纳率: 100%
浏览 93

从php扩展调用compact()到C ++

Here is my code:

  zval compact, compact_params[1], compact_result;
      zval A;
      ZVAL_STRING(&A, "test");
      ZVAL_STRING(&compact, "compact");
      ZVAL_STRING(&compact_params[0], "A");
      call_user_function(EG(function_table), NULL, &compact, &compact_result, 1, compact_params);

when I call it from php it says:

Cannot call compact() dynamically

I dont have any idea now how to call the compact() from c++. I already called different function successfully but this compact is different.

  • 写回答

1条回答 默认 最新

  • dongxuan2015 2018-09-12 22:26
    关注

    It appears PHP 7 added dynamic call protection to certain functions. See this unit test file from the PHP source repository. I'm not sure what the purpose of this is. Your code works in PHP 5 though; I verified it.

    As a workaround, you can look at the implementation of the compact function and use its underlying utility functions to accomplish the same thing. Look at the implementation of php_compact_var(). Since this functionality is statically linked, you'll have to copy the code into your extension.

    评论

报告相同问题?