- Output for 8.1.0 - 8.1.30, 8.2.0 - 8.2.25, 8.3.0 - 8.3.14
- 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);