Skip to content
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

Remove randominess from spl_object_hash #7010

Merged
merged 1 commit into from May 19, 2021
Merged

Conversation

mvorisek
Copy link
Contributor

@mvorisek mvorisek commented May 18, 2021

see https://3v4l.org/b4Z1G and https://github.com/php/php-src/blob/php-8.0.6/ext/spl/php_spl.c#L644-L670

related with #2611

Unneeded randominess is not good as output of repeated runs of php scripts can differ.

I think spl_object_hash should be even deprecated in favor of spl_object_id.

ext/spl/php_spl.c Outdated Show resolved Hide resolved
@mvorisek mvorisek changed the title spl_object_hash does not need randominess Remove randominess from spl_object_hash May 18, 2021
ext/spl/php_spl.c Outdated Show resolved Hide resolved
ext/spl/php_spl.c Outdated Show resolved Hide resolved
@Girgias Girgias merged commit fd8770e into php:master May 19, 2021
@mvorisek mvorisek deleted the patch-1 branch May 19, 2021 06:39
@TysonAndre
Copy link
Contributor

LGTM as the author of the spl_object_id PR

Aside: As nikic said, strpprintf(32, "%016zx0000000000000000", (intptr_t)obj->handle); is right - substitutes for spl_object_id expect that the handle be in the first 16 bytes when determining the random bits (from var_dump and spl_object_hash output for a single object) and converting back to spl_object_id (the handle)

  • e.g. the symfony polyfill would do that, but that doesn't matter since this is php 8.1

I think deprecating spl_object_hash makes sense - it's much worse than spl_object_id for memory usage and time. Support for php 7.2 was dropped recently, and 7.2 was the version that introduced spl_object_id.

At the time I was looking at it years ago, I wasn't sure if php allowed having two objects share the same handle but different handlers - I asked Nikita a few months ago and php doesn't allow this, so spl_object_hash isn't providing anything useful with the handlers hash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants