get_resource_id()

get_resource_id() — Returns an integer identifier for the given resource.

Built-in function of PHP 8.5. The manual lists it as available in PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

What it does

This function provides a type-safe way for generating the integer identifier for a resource.

Signature

get_resource_id(resource $resource): int

Parameters

ParameterTypeWhat it takes
$resourceresourceThe evaluated resource handle.

Return value

The int identifier for the given resource. This function is essentially an int cast of resource to make it easier to retrieve the resource ID.

Example

A runnable snippet:

$handle = fopen("php://stdout", "w"); echo (int) $handle . "\n"; echo get_resource_id($handle);

Output:

698 698

See also

get_resource_type()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page get_resource_id() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.