note 129626 added to function.get-resource-id
| From: | contact@needlecode.com | Date: | Mon, 01 Jul 2024 20:40:27 +0000 |
| Subject: | note 129626 added to function.get-resource-id | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-221403@lists.php.net to get a copy of this message | ||
<?php
// Polyfill codes for
get_resource_id function by MAMEDUL ISLAM from Bangladesh.
if (!function_exists('get_resource_id')) {
/**
* get_resource_id â Returns an integer identifier for the given resource
*
* - This function provides a type-safe way for generating the integer identifier for a resource.
*
* @param $resource
*
* @return integer
* 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
*/
function get_resource_id($resource) {
// Validate that the input is a resource
if (!is_resource($resource)) {
trigger_error('get_resource_id() expects parameter 1 to be resource, ' .
gettype($resource) . ' given', E_USER_WARNING);
return null;
}
// Create a static array to map resource hash to resource ID
static $resourceMap = [];
$hash = spl_object_hash((object) $resource);
if (!isset($resourceMap[$hash])) {
$resourceMap[$hash] = count($resourceMap) + 1;
}
return $resourceMap[$hash];
}
}
?>
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.137 (proxied: 37.111.222.41)
----
Manual Page -- https://php.net/manual/en/function.get-resource-id.php
Edit -- https://main.php.net/note/edit/129626
Del: integrated -- https://main.php.net/note/delete/129626/integrated
Del: useless -- https://main.php.net/note/delete/129626/useless
Del: bad code -- https://main.php.net/note/delete/129626/bad+code
Del: spam -- https://main.php.net/note/delete/129626/spam
Del: non-english -- https://main.php.net/note/delete/129626/non-english
Del: in docs -- https://main.php.net/note/delete/129626/in+docs
Del: other reasons-- https://main.php.net/note/delete/129626
Reject -- https://main.php.net/note/reject/129626
Search -- https://main.php.net/manage/user-notes.php