PHP Conference Japan 2024

ArgumentCountError

(PHP 7 >= PHP 7.1.0, PHP 8)

簡介

當傳遞給使用者定義函式或方法的引數過少時,會拋出 ArgumentCountError

當傳遞給非可變參數內建函式的引數過多時,也會拋出此錯誤。

類別概要

class ArgumentCountError extends TypeError {
/* 繼承的屬性 */
protected 字串 $message = "";
private 字串 $string = "";
protected 整數 $code;
protected 字串 $file = "";
保護的 整數 $line;
私有的 陣列 $trace = [];
私有的 ?Throwable $previous = null;
/* 繼承的方法 */
公開的 Error::__construct(字串 $message = "", 整數 $code = 0, ?Throwable $previous = null)
最終 公開的 Error::getMessage(): 字串
最終 公開的 Error::getPrevious(): ?Throwable
最終 公開的 Error::getCode(): 整數
最終 公開的 Error::getFile(): 字串
最終 公開的 Error::getLine(): 整數
最終 公開的 Error::getTrace(): 陣列
最終 公開的 Error::getTraceAsString(): 字串
私有的 Error::__clone():
}
新增註釋

使用者貢獻的註釋 1 則註釋

18
T7To7
6 年前
請注意,如果傳遞給內建函式的參數數量無效,則當且僅當您的程式碼處於嚴格模式時,才會拋出 ArgumentCountError 例外。

<?php
declare(strict_types = 1);

try {
echo
strlen('ahmed', 4);
} catch (
ArgumentCountError $e) {
echo
$e->getMessage()';
}
?>
To Top