TypeError

(PHP 7, PHP 8)

简介

会抛出TypeError 的情况:

  • 为类属性设置的值与该属性申明的类型不匹配。
  • 传递给函数的参数类型与函数预期声明的参数类型不匹配。
  • 函数返回的值与声明的函数返回类型不匹配

类摘要

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
}

更新日志

版本说明
7.1.0 当在严格模式下向内置 PHP 函数传递无效数量的参数时,不再抛出 TypeError。 相反,会抛出 ArgumentCountError
To Top