Arginfo Mismatch For Optional Parameters

php.internals

Joseph Montanez

3 years ago
Hello, I am a little confused about this while working on my extension. I've compiled PHP with --enable-debug and this only produces a fatal error when used with that flag, without debug it runs fine. "Fatal error: Arginfo / zpp mismatch during call of raylib\Vector3::__construct()" Here is the c code snippet of my code that produces the error: ZEND_BEGIN_ARG_INFO_EX(arginfo_vector3__construct, 0, 0, 0) ZEND_ARG_TYPE_MASK(0, x, IS_DOUBLE, "0") ZEND_ARG_TYPE_MASK(0, y, IS_DOUBLE, "0") ZEND_ARG_TYPE_MASK(0, z, IS_DOUBLE, "0") ZEND_END_ARG_INFO() PHP_METHOD(Vector3, __construct) { double x; bool x_is_null = 1; double y; bool y_is_null = 1; double z; bool z_is_null = 1; ZEND_PARSE_PARAMETERS_START(0, 3) Z_PARAM_OPTIONAL Z_PARAM_DOUBLE_OR_NULL(x, x_is_null) Z_PARAM_DOUBLE_OR_NULL(y, y_is_null) Z_PARAM_DOUBLE_OR_NULL(z, z_is_null) ZEND_PARSE_PARAMETERS_END(); php_raylib_vector3_object *intern = Z_VECTOR3_OBJ_P(ZEND_THIS); if (x_is_null) { x = 0.0f; } if (y_is_null) { y = 0.0f; } if (z_is_null) { z = 0.0f; } intern->vector3->data = (Vector3) { .x = (float) x, .y = (float) y, .z = (float) z }; } Then the line of PHP code: $position = new Vector3(4.0, 2.0, 4.0); I am confused because these are all optional parameters, and it should work? If I exclude the parameters in my PHP code it works fine. If I swap the following: ZEND_BEGIN_ARG_INFO_EX(arginfo_vector3__construct, 0, 0, 0) ZEND_ARG_TYPE_MASK(0, x, IS_DOUBLE, "0") ZEND_ARG_TYPE_MASK(0, y, IS_DOUBLE, "0") ZEND_ARG_TYPE_MASK(0, z, IS_DOUBLE, "0") ZEND_END_ARG_INFO() For the following: ZEND_BEGIN_ARG_INFO_EX(arginfo_vector3__construct, 0, 0, 0) ZEND_ARG_INFO(0, x) ZEND_ARG_INFO(0, y) ZEND_ARG_INFO(0, z) ZEND_END_ARG_INFO() Then it works fine. Can I not use ZEND_ARG_TYPE_MASK in this context? I only put the type mask with the default value so it works better with PHP's built-in reflection, so is this not possible? I've seen similar uses with Tidy and Soap extensions so I'm a little baffled on why it's an issue here. I think the only difference is that where the ARG_INFO is, is in the header files versus the C files of those extensions. Thanks, Joseph Montanez

Máté Kocsis

3 years ago
Hi, The problem is that your arginfo declares parameters of type double, while you accept the double|null type in ZPP. P.s. i'm not sure based on your message whether you use stubs for declaring symbols, but if that's not the case, then doing so is highly recommended. You can find plenty of examples in php-src (*.stub.php files). Regards, Máté

Joseph Montanez

3 years ago
Máté, Thanks! That was the issue :). All of the c code, including arginfo and stubs are auto generated on my end. I didn't know you could use stubs to generate the arg info, so will need to look into it later. Just for reference the following works: ZEND_BEGIN_ARG_INFO_EX(arginfo_vector3__construct, 0, 0, 0) ZEND_ARG_TYPE_MASK(0, x, MAY_BE_DOUBLE|MAY_BE_NULL, "0") ZEND_ARG_TYPE_MASK(0, y, MAY_BE_DOUBLE|MAY_BE_NULL, "0") ZEND_ARG_TYPE_MASK(0, z, MAY_BE_DOUBLE|MAY_BE_NULL, "0") ZEND_END_ARG_INFO() Thanks, Joseph Montanez On Mon, Jul 31, 2023 at 12:38 PM Máté Kocsis <kocsismate90@gmail.com> wrote: