An example:
<?php
function test($x):int {
return $x;
}
try {
test('ss');
}catch(TypeError $e){
echo "Error !";
}
(PHP 7, PHP 8)
Un TypeError puede ser lanzado cuando:
Versión | Descripción |
---|---|
7.1.0 | Un TypeError ya no se lanza cuando se pasa un número inválido de argumentos a una función PHP incorporada en modo estricto. En su lugar, se lanza un 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();
}