# Arginfo Mismatch For Optional Parameters

- Thread: https://externals.io/message/120872
- Original archive: https://news-web.php.net/php.internals/120872
- Started by Joseph Montanez on 2023-07-31T19:31:14+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #120872 — Joseph Montanez — 2023-07-31T19:31:14+00:00

URL: https://externals.io/message/120872#120872

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

---

## #120873 — kocsismate90@gmail.com — 2023-07-31T19:38:21+00:00

URL: https://externals.io/message/120872#120873 · In reply to: #120872

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é

---

## #120874 — Joseph Montanez — 2023-07-31T20:12:46+00:00

URL: https://externals.io/message/120872#120874 · In reply to: #120873

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


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