Skip to content

Commit

Permalink
Update for pretty closure names in PHP 8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Apr 18, 2024
1 parent cab37b1 commit 57b42d4
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 57b42d4

Please sign in to comment.