There is currently no way to do this in PHP starting with version 5.3.6.
spl_object_hash () does not do what you want - since it processes identifiers when objects are deleted, this will lead to errors (for example) in an object-relational mapmaker trying to track objects in a session.
The description at the top of the documentation page ("This function returns a unique identifier for an object. This identifier can be used as a hash key for storing objects or for identifying an object.") Is incorrect - the truth is in the note on this page: "When an object is destroyed, its hash can be reused for other objects, "or, in other words, the function does not always return a unique identifier and cannot always be used to store or identify objects.
The method demonstrated in this comment may work in some cases, but it is not reliable and will not work sequentially, since an attempt to access the undefined property will call the magic methods __get () and __set (), the results of which are unpredictable.
In conclusion, the short answer to your question (unfortunately) is “no” - there is no such method in PHP, and there is no way to write such a method that will work sequentially for any object.
If you want this feature to be added to PHP, vote and / or comment here:
http://bugs.php.net/bug.php?id=52657
mindplay.dk Jun 13 '11 at 12:50 2011-06-13 12:50
source share