Mention that arg_info[-1] holds the return info
authorIvan Enderlin <ivan.enderlin@hoa-project.net>
Mon, 2 Sep 2019 11:32:40 +0000 (13:32 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 9 Sep 2019 15:42:26 +0000 (17:42 +0200)
I lost some time trying to know how to find the returned type.
It's not that obvious it is stored in the _argument_ information array.

For the sake of Internet, here is the full code checking that a function _has_ a returned type:

```c
zend_function *function = /* e.g. fci_cache->function_handler */;

if (!(function->op_array.fn_flags & ZEND_ACC_HAS_RETURN_TYPE)) {
    php_printf("no return type\n");
} else {
    php_printf("has a return type\n");
    php_printf("return type = %s\n", zend_get_type_by_const(ZEND_TYPE_CODE(function->common.arg_info[-1].type)));
}
```

Zend/zend_compile.h

index ea6fe87d45b1ca84ec1ad55129b43468803bb5dc..61b71cbc061e2b375732a38680c224bcc520d0af 100644 (file)
@@ -483,7 +483,7 @@ union _zend_function {
                zend_function *prototype;
                uint32_t num_args;
                uint32_t required_num_args;
-               zend_arg_info *arg_info;
+               zend_arg_info *arg_info;  /* index -1 represents the return value info, if any */
        } common;
 
        zend_op_array op_array;