An example:
<?php
function test($x):int {
return $x;
}
try {
test('ss');
}catch(TypeError $e){
echo "Error !";
}
(PHP 7, PHP 8)
Um TypeError pode ser lançado quando:
Versão | Descrição |
---|---|
7.1.0 | Um erro TypeError não é lançado quando um número inválido de argumentos é passaod para uma função nativa, no modo estrito. Lança agora um erro ArgumentCountError. |
An example:
<?php
function test($x):int {
return $x;
}
try {
test('ss');
}catch(TypeError $e){
echo "Error !";
}
<?php
declare(strict_types=1);
function sumarEnteros(int $entero1, int $entero2): int | float {
return ($entero1 + $entero2)/3 ;
}
$resultado = sumarEnteros(2, 6);
echo $resultado;
?>
<!DOCTYPE html>
<html>
<head>
<title>Suma en PHP</title>
</head>
<body>
</body>
</html>
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();
}