TypeError

(PHP 7, PHP 8)

Introducere

There are three scenarios where a TypeError may be thrown. The first is where the argument type being passed to a function does not match its corresponding declared parameter type. The second is where a value being returned from a function does not match the declared function return type. The third is where an invalid number of arguments are passed to a built-in PHP function (strict mode only).

Sinopsisul clasei

TypeError extends Error {
/* Proprietăți moștenite */
protected string $message ;
protected int $code ;
protected string $file ;
protected int $line ;
/* Metode moștenite */
final public Error::getMessage ( ) : string
final public Error::getPrevious ( ) : Throwable
final public Error::getCode ( ) : mixed
final public Error::getFile ( ) : string
final public Error::getLine ( ) : int
final public Error::getTrace ( ) : array
final public Error::getTraceAsString ( ) : string
public Error::__toString ( ) : string
final private Error::__clone ( ) : void
}
add a note add a note

User Contributed Notes 2 notes

up
0
celsowmbr at outlook dot com
4 years ago
An example:

<?php

function test($x):int {
    return
$x;
}

try {
   
test('ss');
}catch(
TypeError $e){
    echo
"Error !";
}
up
-1
andrian dot test dot job at gmail dot com
4 years ago
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();

}
To Top