An example:
<?php
function test($x):int {
return $x;
}
try {
test('ss');
}catch(TypeError $e){
echo "Error !";
}
(PHP 7, PHP 8)
Ein TypeError kann geworfen werden, wenn:
Version | Beschreibung |
---|---|
7.1.0 | Wenn im Modus strict eine ungültige Anzahl von Argumenten an eine interne PHP-Funktion übergeben wird, wird kein TypeError mehr geworfen; stattdessen wird ein ArgumentCountError geworfen. |
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();
}