Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are PHP resource IDs unique?

Tags:

php

Are PHP resource IDs unique per PHP instance? Does casting all kinds of resources to string returns "Resource id #X" (where X is some decimal number)? Is there a function that returns resource ID (I know about get_resource_type() to get resource typem, but didn't find anything like get_resouce_id()), or does it have to be done like this?

function get_resource_id($resource)
{
    return is_resource($resouce) 
           ? substr((string) $resource, 13 /* strlen("Resource id #") */)
           : NULL;
}
like image 348
Jakub Kulhan Avatar asked Dec 29 '22 09:12

Jakub Kulhan


1 Answers

Easy as it seams

intval($resource)
like image 131
Matias Avatar answered Jan 10 '23 07:01

Matias