(PHP 5 >= 5.5.0, PHP 7, PHP 8, PECL >= 3.0.0a1)
IntlCalendar::getErrorCode -- intlcal_get_error_code — 取得物件上的最後一個錯誤碼
物件導向風格 (方法)
程序式風格
返回此物件(包含複製)上一次呼叫的數值型 ICU 錯誤碼,或是在程序式風格版本中,給定 calendar
參數的 IntlCalendar 的錯誤碼。這可能僅表示警告(負數錯誤碼)或根本沒有錯誤(U_ZERO_ERROR
)。可以使用 intl_is_failure() 測試實際是否存在錯誤。
在 PHP 端偵測到的無效參數(在呼叫 ICU 函式庫的函式之前)不會被此函式記錄。
可以使用 intl_get_error_code() 取得 intl 擴充功能中任何函式呼叫(包括早期參數錯誤)中發生的最後一個錯誤。此函式會重設全域錯誤碼,但不會重設物件的錯誤碼。
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"