Re: New function: spl_object_id() or spl_object_handle()
| From: | Nicolas Grekas | Date: | Tue, 09 Dec 2014 14:39:50 +0000 |
| Subject: | Re: New function: spl_object_id() or spl_object_handle() | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-79500@lists.php.net to get a copy of this message | ||
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.
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.
Regards,
Nicolas