
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get Resource ID Using get_resource_id Function in 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
Advertisements