getClosureThis()) { return $closure; } $scope = $reflection->getClosureScopeClass(); $name = $reflection->getShortName(); if ($name !== '{closure}') { /** @psalm-suppress InvalidScope @phpstan-ignore-next-line @phan-suppress-next-line PhanUndeclaredThis */ $closure = fn (...$args) => $this->$name(...$args); if ($scope !== null) { $closure = $closure->bindTo(null, $scope->name); } } static $placeholder; $placeholder ??= new stdClass(); $closure = $closure->bindTo($placeholder); $ref = WeakReference::create($target); /** @psalm-suppress PossiblyInvalidFunctionCall */ return $scope && get_class($target) === $scope->name && !$scope->isInternal() ? static fn (...$args) => ($obj = $ref->get()) ? $closure->call($obj, ...$args) : null : static fn (...$args) => ($obj = $ref->get()) ? $closure->bindTo($obj)(...$args) : null; }