TypeError

(PHP 7)

Вступ

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).

Короткий Огляд Класа

TypeError extends Error {
/* Успадковані методи */
abstract public string Throwable::getMessage ( void )
abstract public int Throwable::getCode ( void )
abstract public string Throwable::getFile ( void )
abstract public int Throwable::getLine ( void )
abstract public array Throwable::getTrace ( void )
abstract public string Throwable::getTraceAsString ( void )
abstract public Throwable Throwable::getPrevious ( void )
abstract public string Throwable::__toString ( void )
}
add a note add a note

User Contributed Notes 2 notes

up
0
celsowmbr at outlook dot com
5 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