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.
The macro ZEND_BEGIN_ARG_INFO_EX
can be used to provide Zend Engine with information about the function's arguments. The 4th parameter of the macro, named as required_num_args
, 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.
Here is my definition of function arguments:
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()
Here is my definition of the functions, exported by the PHP extension:
static const zend_function_entry test_func_functions[] = {
PHP_FE(sample_with_types, test_func_swt_arginfo)
PHP_FE_END
};
Here is my function:
PHP_FUNCTION(sample_with_types)
{
RETURN_TRUE;
}
Here is the PHP script I run:
<?php
sample_with_types();
Expected result: PHP shows error/warning/exception, something like "not enough arguments are passed to the function"; the function doesn't execute.
Actual result: the function executes and returns true
.
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 required_num_args
argument in ZEND_BEGIN_ARG_INFO_EX
macro?
required_num_args
parameter. It seemed like auto-validation of args num, but in practice it does nothing. Could it be, that you know its purpose? – Mclin