Skip to content

Commit 1e4721d

Browse files
committed
Dumper: prints closures as func(...) in PHP 8.1
1 parent 8185e0c commit 1e4721d

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/PhpGenerator/Dumper.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ private function dumpObject(&$var, array $parents, int $level): string
129129
} elseif ($var instanceof \Closure) {
130130
$inner = Nette\Utils\Callback::unwrap($var);
131131
if (Nette\Utils\Callback::isStatic($inner)) {
132-
return '\Closure::fromCallable(' . $this->dump($inner) . ')';
132+
return PHP_VERSION_ID < 80100
133+
? '\Closure::fromCallable(' . $this->dump($inner) . ')'
134+
: implode('::', (array) $inner) . '(...)';
133135
}
134136
throw new Nette\InvalidArgumentException('Cannot dump closure.');
135137
}

tests/PhpGenerator/Dumper.dump().phpt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,16 @@ Assert::exception(function () {
129129

130130
// closures
131131
Assert::same(
132-
"\\Closure::fromCallable('strlen')",
132+
PHP_VERSION_ID < 80100
133+
? "\\Closure::fromCallable('strlen')"
134+
: 'strlen(...)',
133135
$dumper->dump(Closure::fromCallable('strlen'))
134136
);
135137

136138
Assert::same(
137-
"\\Closure::fromCallable(['Nette\\PhpGenerator\\ClassType', 'from'])",
139+
PHP_VERSION_ID < 80100
140+
? "\\Closure::fromCallable(['Nette\\PhpGenerator\\ClassType', 'from'])"
141+
: 'Nette\PhpGenerator\ClassType::from(...)',
138142
$dumper->dump(Closure::fromCallable([Nette\PhpGenerator\ClassType::class, 'from']))
139143
);
140144

0 commit comments

Comments
 (0)