Add get_resource_id() function

Behavior is same as for (int) $resource, just under a clearer
name. Also type-safe, in that the parameter actually needs to
be a resource.

Closes GH-5427.
This commit is contained in:
Nikita Popov 2020-04-21 12:31:17 +02:00
parent d5d99ce8d1
commit a0abc26ef7
5 changed files with 44 additions and 0 deletions

View file

@ -1495,6 +1495,20 @@ ZEND_FUNCTION(get_resource_type)
}
/* }}} */
/* {{{ proto int get_resource_id(resource res)
Get the resource ID for a given resource */
ZEND_FUNCTION(get_resource_id)
{
zval *resource;
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_RESOURCE(resource)
ZEND_PARSE_PARAMETERS_END();
RETURN_LONG(Z_RES_HANDLE_P(resource));
}
/* }}} */
/* {{{ proto array get_resources([string resource_type])
Get an array with all active resources */
ZEND_FUNCTION(get_resources)