Nicolas Grekas wrote on 09/12/2014 14:39:
Hi Rowan,

        In order to get an object's id, I use a trick that works for now:
        
https://github.com/symfony/symfony/blob/2.6/src/Symfony/Component/VarDumper/Cloner/VarCloner.php#L258-L282


    This seems like a very elaborate piece of reverse engineering


Right, and I made the claim for this being a trick :)

Still: the exact value is not what I'm most interested in you're right (but it provides rought information about the number of objects currently allocated which might be useful sometimes).

The gain is displaying a shortest possible number. I could rehash you're right, but then I'll have collisions. Both arguments (short+unique number) are relevant when debugging/dumping.

Yes, I think a version of spl_object_hash that was more human-readable would be a sensible move. IMHO, it would not be a BC break to completely change the output, since the documentation makes no promises about it, and reverse-engineered code like yours could just check PHP_VERSION.



        
https://github.com/symfony/symfony/tree/2.6/src/Symfony/Component/Debug/Resources/ext


    The more interesting part of this is the refcount


That, plus the fact that it returns the value (instead of writing it to php://output) but other returned values are also important, especially zval_hash and zval_isref that allow efficient tracking of hard references.

Indeed. A non-function version of debug_zval_dump which could do this on any variable would be even better (if I read it right, your function only works on array members?)

--
Rowan Collins
[IMSoP]

Reply via email to