TypeError

(PHP 7, PHP 8)

Introduction

A TypeError may be thrown when:

  • The value being set for a class property does not match the property's corresponding declared type.
  • The argument type being passed to a function does not match its corresponding declared parameter type.
  • A value being returned from a function does not match the declared function return type.

Class synopsis

classTypeErrorextendsError {
protectedstring$message = "";
privatestring$string = "";
protectedint$code;
protectedstring$file = "";
protectedint$line;
privatearray$trace = [];
private?Throwable$previous = null;
publicError::__construct(string$message = "", int$code = 0, ?Throwable$previous = null)
finalpublicError::getCode(): int
finalpublicError::getFile(): string
finalpublicError::getLine(): int
finalpublicError::getTrace(): array
}

Changelog

VersionDescription
7.1.0 A TypeError is no longer thrown when an invalid number of arguments are passed to a built-in PHP function in strict mode. Instead, an ArgumentCountError is raised.
To Top