On 3 August 2015 11:52:06 BST, Nicolas Grekas <nicolas.grekas+...@gmail.com> wrote: >> So, yes, just to make it more human friendly. In which case, the >actual >> value doesn't matter, and rather than reverse-engineering the hash, >you >> could just make up your own ID: >> >> function my_object_id($obj) { >> static $hash_to_id=[]; >> $hash = spl_object_hash($obj); >> if ( ! array_key_exists($hash, $hash_to_id) ) { >> $hash_to_id[$hash] = count( $hash_to_id); >> } >> return $hash_to_id[$hash]; >> } >> > > >Yep, that would work, but with the following drawbacks: >- it would create a memory leak/overhead
If you're dumping so many objects that the array would grow to noticeable size, you're likely to have bigger problems actually using the output. There's probably more data in an optimised autoloader classmap than most people will generate with a function like this. >- more importantly for users, these ids couldn't be compared to >var_dumps'. Why do you need to compare the output of two dump functions? Just add a note to the documentation that these are not the same IDs. Regards, -- Rowan Collins [IMSoP] -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php