6. New Functions
========================================
+- Core:
+ . Added get_resource_id($resource) function, which returns the same value as
+ (int) $resource. It provides the same functionality under a clearer API.
+
- PCRE:
. Added preg_last_error_msg(), which returns a human-readable message for
the last PCRE error. It complements preg_last_error(), which returns an
--- /dev/null
+--TEST--
+get_resource_id() function
+--FILE--
+<?php
+
+$file = fopen(__FILE__, 'r');
+
+// get_resource_id() is equivalent to an integer cast.
+var_dump(get_resource_id($file) === (int) $file);
+
+// Also works with closed resources.
+fclose($file);
+var_dump(get_resource_id($file) === (int) $file);
+
+?>
+--EXPECT--
+bool(true)
+bool(true)
}
/* }}} */
+/* {{{ 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)
function get_resource_type($res): string {}
+function get_resource_id($res): int {}
+
function get_resources(string $type = UNKNOWN): array {}
function get_loaded_extensions(bool $zend_extensions = false): array {}
ZEND_ARG_INFO(0, res)
ZEND_END_ARG_INFO()
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_get_resource_id, 0, 1, IS_LONG, 0)
+ ZEND_ARG_INFO(0, res)
+ZEND_END_ARG_INFO()
+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_get_resources, 0, 0, IS_ARRAY, 0)
ZEND_ARG_TYPE_INFO(0, type, IS_STRING, 0)
ZEND_END_ARG_INFO()
ZEND_FUNCTION(get_defined_functions);
ZEND_FUNCTION(get_defined_vars);
ZEND_FUNCTION(get_resource_type);
+ZEND_FUNCTION(get_resource_id);
ZEND_FUNCTION(get_resources);
ZEND_FUNCTION(get_loaded_extensions);
ZEND_FUNCTION(get_defined_constants);
ZEND_FE(get_defined_functions, arginfo_get_defined_functions)
ZEND_FE(get_defined_vars, arginfo_get_defined_vars)
ZEND_FE(get_resource_type, arginfo_get_resource_type)
+ ZEND_FE(get_resource_id, arginfo_get_resource_id)
ZEND_FE(get_resources, arginfo_get_resources)
ZEND_FE(get_loaded_extensions, arginfo_get_loaded_extensions)
ZEND_FE(get_defined_constants, arginfo_get_defined_constants)