
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
How to get resource ID using get_resource_id() function in PHP and PHP 8?
The resource is a type of variable that holds a reference to an external resource. The resource can be a filehandle, a database connection, or a URL handle. Every resource is identified by a unique id. In the previous versions of PHP, we needed to cast a resource to int to get the resource id.
Example: get_recource_id using int.
<?php $x = fopen('test.txt', 'rb'); $id = (int) $x; print_r($id); ?>
Output
1
In PHP 8, the get_resource_id() function always returns an int. It is used to get the ID for a given resource. This function always guarantees type safety.
Example: Using get_recource_id in PHP 8.
<?php $x = fopen('test.txt', 'rb'); echo get_resource_id($x); ?>
Output
1
- Related Articles
- How to get Resource name using Resource id in Android?
- How to get Resource Name using Resource id in Android using Kotlin?
- PHP Regex to get YouTube Video ID
- How to get the clipping rectangle using imagegetclip() function in PHP?
- How to get current function name in PHP?
- fdiv() function in PHP 8
- str_starts_with and str_ends_with function in PHP 8
- How to get or set the resolution of an image using imageresolution() function in PHP?
- PHP – How to get the modulus of an arbitrary precision number using bcmod() function?
- How to destroy an image in PHP using imagedestroy() function?
- How to draw an ellipse using imageellipse() function in PHP?
- How to draw a line using imageline() function in PHP?
- PHP – How to get the substitution character using mb_substitute_character()?
- Difference between gettype() in PHP and get_debug_type() in PHP 8
- PHP – How to get the square root of an arbitrary precision number using bcsqrt() function?

Advertisements