<?php
$radius = 2;
$circumference = (fn($pi) => $pi * $radius ** 2)(pi());
var_export([
$pi ?? 'Not Declared',
$radius,
$circumference
]);
echo "\n---\n";
$radius = 2;
$circumference = (fn() => pi() * ++$radius ** 2)();
var_export([
$radius, // not 3
$circumference
]);
echo "\n---\n";
$radius = 2;
$circumference = (function() use (&$radius) {
return pi() * ++$radius ** 2;
})();
var_export([
$radius, // changed to 3
$circumference
]);
echo "\n---\n";
$circumference = (fn($pi, $r, $pow) => $pi * $r ** $pow)(pi(), 2, 2);
var_export($circumference);
- Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
- array (
0 => 'Not Declared',
1 => 2,
2 => 12.566370614359172,
)
---
array (
0 => 2,
1 => 28.274333882308138,
)
---
array (
0 => 3,
1 => 28.274333882308138,
)
---
12.566370614359172
preferences:
74.98 ms | 402 KiB | 62 Q