diff --git a/core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php b/core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php
index 4c6f40c6da..6bb4774506 100644
--- a/core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php
+++ b/core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php
@@ -1000,9 +1000,10 @@ public function testNonArrayReturnFromLazyBuilderArrayCallable() {
    */
   public function testNonArrayReturnFromLazyBuilderClosure() {
     $element = [];
-    $element['#lazy_builder'] = [function () {
+    $closure = function () {
       return NULL;
-    }, []];
+    };
+    $element['#lazy_builder'] = [$closure, []];
 
     $this->expectException(\LogicException::class);
     $this->expectExceptionMessage('#lazy_builder callbacks must return a valid renderable array, got NULL from [closure]');
