CakeFest 2024: The Official CakePHP Conference

IntlCalendar::getErrorCode

intlcal_get_error_code

(PHP 5 >= 5.5.0, PHP 7, PHP 8, PECL >= 3.0.0a1)

IntlCalendar::getErrorCode -- intlcal_get_error_codeオブジェクトに関する直近のエラーコードを取得する

説明

オブジェクト指向型 (method):

public IntlCalendar::getErrorCode(): int|false

手続き型:

intlcal_get_error_code(IntlCalendar $calendar): int|false

このオブジェクトの直近の呼び出し (clone も含みます) に関する ICU エラーコードを返します。 または、(手続き型の場合) calendar に指定された IntlCalendar に関する 直近のエラーコードを返します。 これは、単に警告を示している場合 (負のエラーコード) もあれば、 全くエラーがないことを示す場合 (U_ZERO_ERROR) もあります。 実際にエラーがあったかどうかをチェックする場合、 intl_is_failure() が使えます。

(ICU ライブラリを呼び出す前に) PHP 側で不正な引数を検知した場合は、 この関数で検知できる情報として記録されません。

intl 拡張モジュールの関数をコールした際に発生した直近のエラーは、 以前の引数エラーも含めて、 intl_get_error_code() で取得できます。 この関数はグローバルなエラーコードをリセットしますが、 オブジェクトのエラーコードはリセットしません。

パラメータ

calendar

手続き型のインターフェイスで指定する、カレンダーオブジェクト

戻り値

成功、失敗、または警告を示す ICU エラーコードを返します。 失敗した場合は false を返します。

例1 IntlCalendar::getErrorCode()IntlCalendar::getErrorMessage() の例

<?php
ini_set
("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "nl");

$intlcal = new IntlGregorianCalendar(2012, 1, 29);
var_dump(
$intlcal->getErrorCode(),
$intlcal->getErrorMessage()
);
$intlcal->fieldDifference(-1e100, IntlCalendar::FIELD_SECOND);

var_dump(
$intlcal->getErrorCode(),
$intlcal->getErrorMessage()
);

上の例の出力は以下となります。

int(0)
string(12) "U_ZERO_ERROR"

Warning: IntlCalendar::fieldDifference(): intlcal_field_difference: Call to ICU method has failed in /home/glopes/php/ws/example.php on line 10
int(1)
string(81) "intlcal_field_difference: Call to ICU method has failed: U_ILLEGAL_ARGUMENT_ERROR"

参考

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top