-
Notifications
You must be signed in to change notification settings - Fork 7.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
spl_object_id
should never reuse an old value
#7862
Comments
This is basically a duplicate of https://bugs.php.net/52657, which has been closed as WONTFIX. Can you give a use-case where you need a unique ID, which cannot be solved by existing means? |
simple example:
Currently, lookup by a) the original object stored |
Yes. My point is, what is the advantage of reusing the returned value when it can be unique? |
As is, But maybe the more relevant question is, why would you need a unique value, if you can already accomplish your use case with a WeakMap? |
Declining for reasons articulated above. |
Description
spl_object_id
is often used as a key to store/cache some data related to a specific object instance.Current behaviour
Currently the returned value can be resused for another object when the original object was released from memory. When the returned value can be resused, it does not provide huge benefit for the user.
Improved behaviour
This is a feature request to update
spl_object_id
to return always a new/unique value. When the returned value is always guaranteed to be never reused per php instance lifetime, user can rely on this fact without having to further compare the object instance equality (which requires storing the original object reference or some additional value).x86 version should maintain this new behaviour until all positive integers are used/returned, then reusing of released values can be allowed (preferably with some way to check the exhaustion from user code)
x64 version positive integers space is enough to never overflow in php instance lifetime (would take 292 years to exhaust when every 1ns would be created 1 object [1])
[1] https://www.google.com/search?q=%3D(2^63%2F10^9)%2F(3600*24*365)
The text was updated successfully, but these errors were encountered: