Nicolas Grekas wrote on 09/12/2014 09:31:
Hi
this is a proposal to add new function to PHP core: spl_object_id()
IMHO this is a good idea: currently, var_dump has this super-power (and
super-useful) capability of outputting a number that ease recognizing
identical objects in dumps. This power should be transferred to userland
devs so they can build their own tools.
In fact, that's what I've done: since Symfony 2.6, you can dump using a
userland function that (IMHO again) is more powerful than var_dump:
http://symfony.com/doc/current/components/var_dumper/introduction.html
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 for very
little gain. If you just want to turn the result of spl_object_hash into
a consistent integer, just use whatever re-hashing you like. The exact
value of the "object handle" is not something you could ever do anything
with anyway, surely?
But I'd prefer replacing this trick by a dedicated function. So, with
Julien Pauli, we worked on such a function. Symfony 2.6 also embeds a PHP
extension that exposes more meta data about variables:
https://github.com/symfony/symfony/tree/2.6/src/Symfony/Component/Debug/Resources/ext
The function implemented in this extension is the root primitive that
enables building a feature-full dumper, without resorting to tricks in PHP.
The more interesting part of this is the refcount - unlike
spl_object_hash(), which does its job just fine, debug_zval_dump() *is*
broken, because the documented use requires call-time pass-by-reference,
which is actually impossible in current versions of PHP. A replacement
would presumably need to hook in as a language construct rather than a
function, so that the function call itself doesn't mess up the refcount
and is_ref status of a ZVAL?
Regards,
--
Rowan Collins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php