I\'ve learn a while ago on StackOverflow that we can get the \"instance ID\" of any resource, for instance:
var_dump(intval(curl_init())); // int(2)
var_dum
Alix, your solution in the question was exactly what I needed, but actually breaks when there's an object in an object, returns the last # in the var_dump. I fixed this, made the regex faster, and put it in a nice little function.
/**
* Get global object ID
* From: http://stackoverflow.com/questions/2872366/get-instance-id-of-an-object-in-php
* By: Alix Axel, non-greedy fix by Nate Ferrero
*/
function get_object_id(&$obj) {
if(!is_object($obj))
return false;
ob_start();
var_dump($obj);// object(foo)#INSTANCE_ID (0) { }
preg_match('~^.+?#(\d+)~s', ob_get_clean(), $oid);
return $oid[1];
}