Fix spl_object_hash deprecation on PHP 8.6 - #254
Open
jtojnar wants to merge 2 commits into
Open
Conversation
jtojnar
force-pushed
the
php86-deprecation
branch
from
September 3, 2026 02:44
4547983 to
c0df6da
Compare
The 1.x branch has long been abandoned and it contains many security issues but we cannot switch to 2.x while we still support PHP 7.1. It is only used for tests so it should be safe enough.
When testing with PHP 8.6.0beta2, I get the following deprecation warning:
Function spl_object_hash() is deprecated since 8.6, consider using spl_object_id() instead
Let’s switch to the suggested function where supported.
https://www.php.net/manual/en/function.spl-object-hash.php
https://www.php.net/manual/en/function.spl-object-id.php
jtojnar
force-pushed
the
php86-deprecation
branch
2 times, most recently
from
September 3, 2026 03:02
e0fa0b8 to
52920f9
Compare
jtojnar
commented
Sep 3, 2026
| $uri = $this->createUri($response, $request); | ||
| $redirectRequest = $this->buildRedirectRequest($request, $uri, $statusCode); | ||
| $chainIdentifier = spl_object_hash((object) $first); | ||
| $chainIdentifier = \PHP_VERSION_ID < 70200 ? spl_object_hash((object) $first) : (string) spl_object_id((object) $first); |
Author
There was a problem hiding this comment.
I am surprised this ever worked. According to docs:
This id can be used as a hash key for storing objects, or for identifying an object, as long as the object is not destroyed. Once the object is destroyed, its hash may be reused for other objects.
And indeed, running:
var_dump(spl_object_hash((object) ['a', 'b']));
var_dump(spl_object_hash((object) ['a', 'b', 'c']));
var_dump(spl_object_hash((object) md5(...)));Prints the following for me:
string(32) "00000000000000020000000000000000"
string(32) "00000000000000020000000000000000"
string(32) "00000000000000020000000000000000"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's in this PR?
Switch to the suggested non-deprecated function where supported.
https://www.php.net/manual/en/function.spl-object-hash.php
https://www.php.net/manual/en/function.spl-object-id.php
Why?
When testing with PHP 8.6.0beta2, I get the following deprecation warning:
Example Usage
N/A
Checklist