An example:
<?php
function test($x):int {
return $x;
}
try {
test('ss');
}catch(TypeError $e){
echo "Error !";
}
(PHP 7, PHP 8)
TypeError がスローされるのは、以下の場合です:
バージョン | 説明 |
---|---|
7.1.0 | strict モードの場合に、 PHP の組み込みの関数に渡す引数の数を間違えた場合でも、 TypeError はスローされなくなりました。 代わりに、 ArgumentCountError がスローされるようになっています。 |
An example:
<?php
function test($x):int {
return $x;
}
try {
test('ss');
}catch(TypeError $e){
echo "Error !";
}
declare(strict_types=1); //if without this line the result is different
$a = [1,2=>[3,4]];
try{
count($a, COUNT_RECURSIVE, 'toto and blabla');
}catch(TypeError $e){
echo $e->getMessage();
}