Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make ZEND_BEGIN_ARG_INFO_EX control number of arguments, passed to a PHP extension?
    text
    copied!<p>I'm developing a PHP extension, using C. So far I'm working on the proper validation of arguments, passed to the extension's function from PHP userspace. </p> <p>The macro <code>ZEND_BEGIN_ARG_INFO_EX</code> can be used to provide Zend Engine with information about the function's arguments. The 4th parameter of the macro, named as <code>required_num_args</code>, let the engine automatically control the number of arguments, removing this hassle from me. However, I couldn't find the way to make it work: the engine always runs the extension's function without any warnings, even if a PHP script doesn't pass there enough arguments.</p> <p>Here is my definition of function arguments:</p> <pre><code>ZEND_BEGIN_ARG_INFO_EX(test_func_swt_arginfo, 0, 0, 3) ZEND_ARG_INFO(1, firstArg) ZEND_ARG_ARRAY_INFO(0, secondArg, true) ZEND_ARG_OBJ_INFO(1, thirdArg, SomeClass, false) ZEND_END_ARG_INFO() </code></pre> <p>Here is my definition of the functions, exported by the PHP extension:</p> <pre><code>static const zend_function_entry test_func_functions[] = { PHP_FE(sample_with_types, test_func_swt_arginfo) PHP_FE_END }; </code></pre> <p>Here is my function:</p> <pre><code>PHP_FUNCTION(sample_with_types) { RETURN_TRUE; } </code></pre> <p>Here is the PHP script I run:</p> <pre><code>&lt;?php sample_with_types(); </code></pre> <p>Expected result: PHP shows error/warning/exception, something like <em>"not enough arguments are passed to the function"</em>; the function doesn't execute.</p> <p>Actual result: the function executes and returns <code>true</code>.</p> <p>How can I properly configure the function arguments structure, so that Zend Engine check the number of arguments automatically? Or do I mistake the purpose of <code>required_num_args</code> argument in <code>ZEND_BEGIN_ARG_INFO_EX</code> macro?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload