範例
<?php
function test($x):int {
return $x;
}
try {
test('ss');
}catch(TypeError $e){
echo "Error !";
}
(PHP 7, PHP 8)
當以下情況發生時,可能會拋出 TypeError:
$message
= "", 整數 $code
= 0, ?Throwable $previous
= null
)版本 | 說明 |
---|---|
7.1.0 | 在嚴格模式下,當傳遞給內建 PHP 函式的參數數量無效時,不再拋出 TypeError。而是會引發 ArgumentCountError。 |
範例
<?php
function test($x):int {
return $x;
}
try {
test('ss');
}catch(TypeError $e){
echo "Error !";
}