查詢

IntlTimeZone::getErrorCode()函式—用法及示例

「 獲取上一次呼叫IntlTimeZone方法時產生的錯誤程式碼 」


函式名稱:IntlTimeZone::getErrorCode() 

適用版本:PHP 5 >= 5.5.0, PHP 7, PHP 8

函式描述:獲取上一次呼叫IntlTimeZone方法時產生的錯誤程式碼。

用法:

public IntlTimeZone::getErrorCode(): int|false

引數: 此函式不接受任何引數。

返回值:

  • 如果沒有錯誤發生,返回一個非負整數,表示沒有錯誤。
  • 如果有錯誤發生,返回一個負整數,表示錯誤程式碼。

示例:

// 例項化IntlTimeZone物件
$timeZone = new IntlTimeZone('America/New_York');

// 獲取錯誤程式碼
$errorCode = $timeZone->getErrorCode();

// 檢查是否有錯誤發生
if ($errorCode === IntlTimeZone::ERROR_NONE) {
    echo "沒有錯誤發生。";
} else {
    echo "發生錯誤,錯誤程式碼為:" . $errorCode;
}

在上述示例中,我們例項化了一個IntlTimeZone物件,並使用'America/New_York'作為時區識別符號。然後,我們使用getErrorCode()方法獲取上一次呼叫IntlTimeZone方法時產生的錯誤程式碼。最後,我們根據錯誤程式碼的值,判斷是否發生了錯誤,並輸出相應的訊息。

補充糾錯
熱門PHP函式
分享連結