@ 2023-10-11T10:34:37Z <?php
class Database {}
$fns = [
function ($str) {},
function ($str ="hello") {},
function (string $str) {},
function (string $str = null) {},
function (?string $str) {},
function (?Database $db) {},
function (Database $db = new Database()) {},
function (string|null $str) {},
function (string $str = "hello") {},
function (?string $str = "hello") {},
function (string|int $str) {},
function (string|null $str = null) {},
function (string|null $str = "hello") {},
];
echo "parameter\tallowsNull\tisOptional\tgetDefaultValue\tgetType\n";
foreach ($fns as $fn) {
$param = (new ReflectionFunction($fn))->getParameters()[0];
echo substr($param->__toString(), 26, -2)
. "\t" . json_encode($param->allowsNull())
. "\t" . json_encode($param->isOptional())
. "\t" . ($param->isDefaultValueAvailable() ? str_replace("\n", "", print_r($param->getDefaultValue(), true)) : "throws ReflectionException")
. "\t" . ($param->getType() ? get_class($param->getType()) : "null")
. "\n";
}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 8.3.0 0.011 0.008 28.09 8.2.11 0.008 0.003 20.24 8.2.10 0.002 0.009 18.84 8.0.11 0.010 0.008 28.09 7.4.33 0.020 0.003 28.09 5.6.40 0.008 0.076 25.66
preferences:dark mode live preview
128.74 ms | 1398 KiB | 7 Q