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.
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.