CKTIS / PHP
TypeError
Meldt een waarde die niet aan het vereiste argument- of retourtype voldoet. strict_types voorkomt de meeste scalaire omzettingen bij aanroepen van eigen functies. int voldoet nog steeds aan float.
Versie: PHP 8.4; repository runtime, production runtime not attested
Syntax
catch (TypeError $failure) { /* handle invalid type */ }Meldt een waarde die niet aan het vereiste argument- of retourtype voldoet. strict_types voorkomt de meeste scalaire omzettingen bij aanroepen van eigen functies. int voldoet nog steeds aan float. TypeError erft van Error en is Throwable.
declare(strict_types=1);
function twice(int $n): int{return $n*2;}
try{twice("2");}catch(TypeError $e){echo json_encode([twice(2),$e instanceof Error,$e instanceof Throwable]);}
[4,true,true]
Voorbeelden
<?php
declare(strict_types=1);
function twice(int $n): int{return $n*2;}
try{twice("2");}catch(TypeError $e){echo json_encode([twice(2),$e instanceof Error,$e instanceof Throwable]);}
Resultaat
[4,true,true]