Re: Exposing object handles to userland

From: Date: Mon, 03 Aug 2015 11:16:08 +0000
Subject: Re: Exposing object handles to userland
References: 1 2 3 4 5 6 7 8 9  Groups: php.internals 
Request: Send a blank email to internals+get-87569@lists.php.net to get a copy of this message
On 3 August 2015 11:52:06 BST, Nicolas Grekas <nicolas.grekas+php@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]

« previous php.internals (#87569) next »