[php-src] Issue #11695: Argument #1 ($dest) must be of type ?GError, null given
| From: | SVGAnimate | Date: | Thu, 13 Jul 2023 11:09:22 +0000 |
| Subject: | [php-src] Issue #11695: Argument #1 ($dest) must be of type ?GError, null given | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-244958@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/11695
Author: SVGAnimate
### Description
The following code:
```php
<?php
$src = new GError();
//$dest = null;
g_propagate_error($dest, $src);
var_dump($dest);
```
Resulted in this output:
```
Argument #1 ($dest) must be of type ?GError, null given
```
But I expected this output instead:
```
object(GError)#2 (0) {
}
```
<hr />
Hi, I would like to bind the function
g_propagate_error(https://docs.gtk.org/glib/func.propagate_error.html)
I defined the signature as follows :
```php
<?php
function g_propagate_error(?GError &$dest, GError $src);
```
I use
?GError because I want to inform the user that he will get a GError type
In the source code of the extension I declared my arguments as follows :
```c
ZEND_BEGIN_ARG_INFO_EX(arginfo_g_propagate_error, 0, ZEND_SEND_BY_VAL, 2)
ZEND_ARG_OBJ_INFO(ZEND_SEND_BY_REF, dest, GError, 1)
ZEND_ARG_OBJ_INFO(ZEND_SEND_BY_VAL, src, GError, 0)
ZEND_END_ARG_INFO()
PHP_FUNCTION(g_propagate_error);
```
And the function :
```c
PHP_FUNCTION(g_propagate_error)
{
zval *z_ref_dest = NULL;
zval *z_src = NULL;
int check_null = 1;//ZVAL_NULLABLE
int deref = 0;// ZVAL_BY_REF
ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_OBJECT_OF_CLASS_EX(z_ref_dest, php_g_error_class_entry, check_null, deref)
Z_PARAM_OBJECT_OF_CLASS(z_src, php_g_error_class_entry)
ZEND_PARSE_PARAMETERS_END();
// ....
}
```
FYI, without the type, it works using
```c
Z_PARAM_ZVAL_EX2(z_ref_dest, 1, 0, 0)
```
In this case regardless of the parameters (check_null, deref) my variable z_ref_dest will always be
initialized unlike Z_PARAM_OBJECT_OF_CLASS_EX
I modified Z_PARAM_OBJECT_OF_CLASS_EX to correct the error message (must be of type ?GError, null
given) :
```c
zend_parse_arg_object(deref ? _arg : &_arg->value.ref->val, &dest, _ce, check_null)))
```
I would like my z_ref_dest variable to either be initialized to IS_NULL (or not ...)
So my question is:
How do you want it to work?
```c
Z_PARAM_OBJECT_OF_CLASS_EX(z_val, ce, check_null, deref) else Z_PARAM_SET_NULL(z_val, deref)
```
or
```c
Z_PARAM_OBJECT_OF_CLASS_EX(z_val, ce, check_null, deref, optional)
```
Or did I miss something
### PHP Version
master
### Operating System
_No response_