On 28/11/2014 21:06, Marc Bennewitz wrote:
But to have a unique ID for objects sound like a very good idea and
would solve the object as array key issue.
I'm sure it's not as simple as the function prototype explained in
this thread previously.
Indeed. Fortunately, we already have one: it's called spl_object_hash()
If the current limitation of handles being potentially reused (which
would also affect this proposal) can be solved, then it can be done
there without creating a new function, as far as I can see.
For quick comparison, here's the key line of the proposed implementation:
RETURN_LONG(Z_OBJ_HANDLE_P(obj));
And here's the key lines of the spl_object_hash() implementation [1]:
SPL_G(hash_mask_handle) = (intptr_t)(php_mt_rand(TSRMLS_C) >> 1);
SPL_G(hash_mask_handlers) = (intptr_t)(php_mt_rand(TSRMLS_C) >> 1);
...
hash_handle = SPL_G(hash_mask_handle)^(intptr_t)Z_OBJ_HANDLE_P(obj);
hash_handlers = SPL_G(hash_mask_handlers)^(intptr_t)Z_OBJ_HT_P(obj);
return strpprintf(32, "%016lx%016lx", hash_handle, hash_handlers);
So, the existing function varies based on the object's "handle" (the
part the simple implementation would return unhashed), its "handlers",
plus some per-thread randomness.
[1] http://lxr.php.net/xref/PHP_TRUNK/ext/spl/php_spl.c#756
--
Rowan Collins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php