From 57b42d4ad7dd5292ebc4bc1e33556b237f883ee6 Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Thu, 18 Apr 2024 10:22:36 -0500 Subject: [PATCH] Update for pretty closure names in PHP 8.4 --- src/functions.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/functions.php b/src/functions.php index 681be126..05dced59 100644 --- a/src/functions.php +++ b/src/functions.php @@ -150,11 +150,11 @@ function weakClosure(\Closure $closure): \Closure $scope = $reflection->getClosureScopeClass(); $useBindTo = !$scope || $that::class !== $scope->name || $scope->isInternal(); - $method = $reflection->getShortName(); - if ($method !== '{closure}') { + $methodName = $reflection->getShortName(); + if (!\str_starts_with($methodName, '{closure')) { // Closure from first-class callable or \Closure::fromCallable(), declare an anonymous closure to rebind. /** @psalm-suppress InvalidScope Closure is bound before being invoked. */ - $closure = fn (mixed ...$args): mixed => $this->{$method}(...$args); + $closure = fn (mixed ...$args): mixed => $this->{$methodName}(...$args); if ($useBindTo && $scope) { $closure = $closure->bindTo(null, $scope->name); }