- Output for 8.1.0 - 8.1.31, 8.2.0 - 8.2.26, 8.3.0 - 8.3.15, 8.4.1 - 8.4.2
- Do something before the func call. 23 Do something after the func call.
<?php
function decorate(callable $func): callable
{
return function (mixed ...$args) use ($func): mixed {
echo "Do something before the func call.", PHP_EOL;
$result = $func(...$args);
echo "Do something after the func call.", PHP_EOL;
return $result;
};
}
// -------------------------------------------------------
$func = function (int $x): void {
echo $x, PHP_EOL;
};
$func = decorate($func);
$func(x: 23);