Problem/Motivation

Function is deprecated see https://wiki.php.net/rfc/deprecations_php_8_6#deprecate_spl_object_hash

Steps to reproduce

git grep spl_object_hash
core/lib/Drupal/Component/DependencyInjection/ReverseContainer.php:89:    // spl_object_hash's return can be recycled. This still is not a 100%
core/lib/Drupal/Component/DependencyInjection/ReverseContainer.php:92:    // @see https://php.net/spl_object_hash#refsect1-function.spl-object-hash-notes
core/lib/Drupal/Component/DependencyInjection/ReverseContainer.php:93:    return get_class($object) . spl_object_hash($object);
core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php:681:    $prefix_parts[] = spl_object_hash($entity_type);
core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php:683:      $prefix_parts[] = spl_object_hash($storage_definition);
core/lib/Drupal/Core/TypedData/Validation/RecursiveContextualValidator.php:148:    $cache_key = spl_object_hash($data);
core/lib/Drupal/Core/TypedData/Validation/RecursiveContextualValidator.php:218:        $constraint_hash = spl_object_hash($constraint);
core/modules/file/tests/src/Kernel/Formatter/FileEntityFormatterTest.php:168:      $this->assertEquals(spl_object_hash($file), spl_object_hash($build['filemime'][0]['#file']));
core/modules/user/tests/src/Kernel/Field/UserNameFormatterTest.php:82:    $this->assertEquals(spl_object_hash($user), spl_object_hash($result[0]['#account']));
core/modules/user/tests/src/Kernel/Field/UserNameFormatterTest.php:91:    $this->assertEquals(spl_object_hash($user), spl_object_hash($result[0]['#account']));
core/modules/views/tests/src/Kernel/Plugin/DisplayKernelTest.php:115:    $first = spl_object_hash($display_handler->getPlugin('style'));
core/modules/views/tests/src/Kernel/Plugin/DisplayKernelTest.php:116:    $second = spl_object_hash($display_handler->getPlugin('style'));
core/modules/views/tests/src/Kernel/ViewExecutableTest.php:136:    $view_hash = spl_object_hash($view);
core/modules/views/tests/src/Kernel/ViewExecutableTest.php:137:    $display_hash = spl_object_hash($view->display_handler);
core/modules/views/tests/src/Kernel/ViewExecutableTest.php:144:    $this->assertEquals($view_hash, spl_object_hash($view->style_plugin->view));
core/modules/views/tests/src/Kernel/ViewExecutableTest.php:145:    $this->assertEquals($display_hash, spl_object_hash($view->style_plugin->displayHandler));
core/modules/views/tests/src/Kernel/ViewExecutableTest.php:150:    $this->assertEquals($view_hash, spl_object_hash($view->query->view));
core/modules/views/tests/src/Kernel/ViewExecutableTest.php:151:    $this->assertEquals($display_hash, spl_object_hash($view->query->displayHandler));
core/modules/views/tests/src/Kernel/ViewExecutableTest.php:219:    $this->assertEquals(spl_object_hash($view->displayHandlers->get('default')), spl_object_hash($view->display_handler));
core/modules/views/tests/src/Kernel/ViewExecutableTest.php:238:    $this->assertEquals(spl_object_hash($view->displayHandlers->get('default')), spl_object_hash($view->display_handler));
core/modules/views/tests/src/Kernel/ViewExecutableTest.php:241:    $this->assertEquals(spl_object_hash($view->displayHandlers->get('default')), spl_object_hash($view->displayHandlers->get('page_1')->default_display));
core/modules/views/tests/src/Kernel/ViewExecutableTest.php:242:    $this->assertEquals(spl_object_hash($view->displayHandlers->get('default')), spl_object_hash($view->displayHandlers->get('page_2')->default_display));
core/modules/views/tests/src/Kernel/ViewExecutableTest.php:247:    $this->assertEquals(spl_object_hash($view->displayHandlers->get('default')), spl_object_hash($view->display_handler));
core/modules/views/tests/src/Kernel/ViewExecutableTest.php:252:    $this->assertEquals(spl_object_hash($view->displayHandlers->get('page_1')), spl_object_hash($view->display_handler));
core/modules/views/tests/src/Kernel/ViewExecutableTest.php:256:    $this->assertEquals(spl_object_hash($view->displayHandlers->get('page_2')), spl_object_hash($view->display_handler));
core/modules/views/tests/src/Kernel/ViewExecutableTest.php:331:    $this->assertSame(spl_object_hash($view->getResponse()), spl_object_hash($new_response), 'New response object correctly set.');
core/modules/views/tests/src/Unit/ViewsTest.php:83:    $this->assertEquals(spl_object_hash($view), spl_object_hash($executable->storage));
core/tests/Drupal/KernelTests/Core/Entity/EntityTranslationTest.php:1091:    $default_translation_spl_object_hash = spl_object_hash($entity);
core/tests/Drupal/KernelTests/Core/Entity/EntityTranslationTest.php:1092:    $this->assertEquals($default_translation_spl_object_hash, spl_object_hash($entity->getTranslation($translation_langcode)->getTranslation($default_langcode)));
core/tests/Drupal/KernelTests/Core/Entity/EntityTranslationTest.php:1097:    $this->assertEquals(spl_object_hash($entity->getTranslation($translation_langcode)), spl_object_hash($entity->getTranslation($translation_langcode)));
core/tests/Drupal/KernelTests/Core/Entity/EntityTranslationTest.php:1098:    $this->assertEquals(spl_object_hash($entity->getTranslation($translation_langcode)), spl_object_hash($entity->getTranslation($translation_langcode)->getTranslation($default_langcode)->getTranslation($translation_langcode)));
core/tests/Drupal/KernelTests/Core/Routing/RouteProviderTest.php:724:    // spl_object_hash() because they are separate instances.
core/tests/Drupal/Tests/Core/Entity/TypedData/EntityAdapterUnitTest.php:250:    $this->assertSame(spl_object_hash($this->entityAdapter), spl_object_hash($this->entityAdapter->getRoot()));

Proposed resolution

- replace the usage and adjust type where required

Remaining tasks

- patch
- review
- commit

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3616553

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

andypost created an issue. See original summary.

andypost’s picture

Status: Active » Needs review

hope the replacement is safe

godotislate’s picture

Minor comments/nits on the MR. OK to self-RTBC.

longwave’s picture

Status: Needs review » Needs work

Anywhere we compare the object hash/ID in a test to another one, I think we should just use assertSame(), which uses ===, which checks that two objects are the same instance.

longwave-bot made their first commit to this issue’s fork.

longwave’s picture

Status: Needs work » Needs review
godotislate’s picture

Status: Needs review » Reviewed & tested by the community

There was a PHPCS issue with arrays/line lengths after an applied suggestion, so I adjusted that. This lgtm now.