PHP Function Reference

PHP get_resource_id() Function



The PHP get_resource_id() function provides a type-safe way for generating the integer identifier for a resource. This function is an int cast of resource to make it easier to retrieve the resource ID.

Note: This function is available as of PHP 8.0.0.

Syntax

get_resource_id(resource)

Parameters

resource Required. Specify the evaluated resource handle.

Return Value

Returns the int identifier for the given resource.

Example:

Lets assume that we have a file called test.txt in the current working directory. The example below demonstrates on using this function to get integer identifier for this resource.

<?php
$file = 'test.txt';

$fp = fopen($file, 'r');

//integer cast of the resource 
echo (int) $fp . "\n\n";

//getting int identifier using 
//get_resource_id() function
echo get_resource_id($fp);
?>

The output of the above code will be:

5

5

❮ PHP Variable Handling Reference