Re: Exposing object handles to userland

From: Date: Mon, 03 Aug 2015 10:52:06 +0000
Subject: Re: Exposing object handles to userland
References: 1 2 3 4 5 6 7 8  Groups: php.internals 
Request: Send a blank email to internals+get-87568@lists.php.net to get a copy of this message
> 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 - more importantly for users, these ids couldn't be compared to var_dumps'.

« previous php.internals (#87568) next »