(PHP 5 >= 5.3.0, PHP 7, PHP 8)
DateTime::getLastErrors -- date_get_last_errors — 獲取警告和錯誤信息
面向?qū)ο箫L(fēng)格
過程化風(fēng)格
返回在解析日期時間字符串的過程中發(fā)生的警告和錯誤信息。
此函數(shù)沒有參數(shù)。
返回一個數(shù)組,其中包含在解析日期時間字符串的過程中發(fā)生的警告和錯誤信息。
示例 #1 DateTime::getLastErrors() 例程
面向?qū)ο箫L(fēng)格
<?php
try {
$date = new DateTime('asdfasdf');
} catch (Exception $e) {
// 僅出于演示的目的...
print_r(DateTime::getLastErrors());
// 實際的代碼中你應(yīng)該這樣使用返回對象
// echo $e->getMessage();
}
?>
過程化風(fēng)格
<?php
$date = date_create('asdfasdf');
print_r(date_get_last_errors());
?>
以上例程會輸出:
Array ( [warning_count] => 1 [warnings] => Array ( [6] => Double timezone specification ) [error_count] => 1 [errors] => Array ( [0] => The timezone could not be found in the database ) )
返回數(shù)組中的索引 6 和 0 表示在解析過程中,所提供的日期時間字符串中無法正確解析的字符位置。