On Fri, Nov 28, 2014 at 2:14 PM, Sebastian Krebs <krebs....@gmail.com>
wrote:

> 2014-11-28 2:13 GMT+01:00 Bostjan Skufca <bost...@a2o.si>:
>
> > Hello everyone,
> >
> > this is a proposal to add new function to PHP core: spl_object_id()
> >
> >
> > The story:
> > ========
> > Recently I was debugging some larger libraries and sorely missed a
> function
> > that would return an object ID. A function called spl_object_hash()
> exists,
> > but it returns identical hashes for equal objects.
>
>
> It returns unique IDs for existing objects. A hash is only reused only when
> the corresponding object was removed by the GC earlier.
> So actually asking me it makes more sense to "fix" the behaviour of
> spl_object_hash(),
>

yeah, the more I think about it the more I feel that the current
implementation is just a landmine.
you shouldn't store the return value and compare it later, even inside of
the same request, because you could have collision if the object which the
hash belongs gets freed before you compare.
so basically the only safe usage would be the one where you have the two
objects which you want to compare right away, but in that case, you could
also just === them.
I also used spl_object_hash() in the past when traversing/custom
serializing object structures which can have infinite recursions between
objects, but even that could be simply solved by storing the already
traversed objects in an array (as assigning the objects into another
variable doesn't have much overhead) and checking with in_array.
would be nice hearing from others for what else are they using
spl_object_hash() for.

-- 
Ferenc Kovács
@Tyr43l - http://tyrael.hu

Reply via email to