Longhorn PHP 2023 - Call for Papers

TypeError

(PHP 7, PHP 8)

Giriş

TypeError sınıfının yavrulanabildiği durumlar:

  • Bir sınıf özelliğine atanan değerin türü ile özelliğin bildirilen türünün uyuşmaması.
  • Bir işleve aktarılan bağımsız değişken türünün bildirilen bağımsız değişken türü ile uyuşmaması.
  • Bir işlevden dönen bir değerin işlevin bildirilen dönüş türü ile uyuşmaması.

Sınıf Sözdizimi

class TypeError extends Error {
/* Miras alınan özellikler */
protected string $message = "";
private string $string = "";
protected int $code;
protected string $file = "";
protected int $line;
private array $trace = [];
private ?Throwable $previous = null;
/* Miras alınan yöntemler */
public Error::__construct(string $message = "", int $code = 0, ?Throwable $previous = null)
final public Error::getMessage(): string
final public Error::getPrevious(): ?Throwable
final public Error::getCode(): int
final public Error::getFile(): string
final public Error::getLine(): int
final public Error::getTrace(): array
final public Error::getTraceAsString(): string
public Error::__toString(): string
private Error::__clone(): void
}

Sürüm Bilgisi

Sürüm: Açıklama
7.1.0 Katı kodlama kipinde yerleşik bir PHP işlevine geçersiz sayıda bağımsız değişken aktarımında artık TypeError yerine ArgumentCountError yavrulanıyor.
add a note

User Contributed Notes 2 notes

up
4
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
-12
andrian dot test dot job at gmail dot com
3 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