<?php
foreach ([
'boolean' => 'true',
'double' => '1.2',
'integer' => '1',
'resource' => 'STDOUT',
] as $type => $value) {
$functionName = "foo_{$type}";
$code = <<<EOT
function {$functionName}({$type} \$i)
{
}
{$functionName}({$value});
EOT;
echo "Testing {$type} with\n", str_replace($functionName, 'foo', $code), "\nresults in:\n ";
try {
eval($code);
echo "success.\n";
} catch (TypeError $e) {
$message = str_replace($functionName, 'foo', $e->getMessage());
$message = substr($message, 0, strpos($message, ', called in '));
echo $message, "\n";
}
echo "\n";
}
preferences:
59.35 ms | 406 KiB | 5 Q