On 07/31/2015 09:23 AM, Julien Pauli wrote:
Hi people.

I've been pinged many times to add a new spl_object_id() function to PHP,
that would return the internal object handle of an object.

Today, spl_object_hash() partially allows that, but adds many randomness to
the result, which is not very cool to use later  (why does it even add
randomness ?).

There has been topics about this subject.
For example, at http://marc.info/?l=php-internals&m=141814350920452&w=2


Beeing able to get the object handle back in PHP userland would ease many
tools, mainly debug-oriented tools.
I know PHPUnit, Symfony and many big projects today make use of
spl_object_hash() to identify objects.

I also know people that print_r($an_object) and parse the output just to
extract the object handle from there... Crazy isn't it ?
Why couldn't we help those people by simply adding a new function that does
the job ?

Thoughts ?


Julien.Pauli


I can think of several use cases why this might be useful, and not just for debugging-related code. It could be used for indexing some sort of complex object storage data structure (if you can't/won't use SplObjectStorage). I can think of a few libraries that us spl_object_hash() to do the same thing but doesn't work well in conjunction with forking (probably due to the randomness factor).

+1

--
Stephen Coakley

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to