(PHP 5 >= 5.3.0, PHP 7, PHP 8)
DateTime::getLastErrors -- date_get_last_errors — 獲取警告和錯誤信息
面向對象風(fēng)格
過(guò)程化風(fēng)格
返回在解析日期時(shí)間字符串的過(guò)程中發(fā)生的警告和錯誤信息。
此函數沒(méi)有參數。
返回一個(gè)數組,其中包含在解析日期時(shí)間字符串的過(guò)程中發(fā)生的警告和錯誤信息。
示例 #1 DateTime::getLastErrors() 例程
面向對象風(fēng)格
<?php
try {
$date = new DateTime('asdfasdf');
} catch (Exception $e) {
// 僅出于演示的目的...
print_r(DateTime::getLastErrors());
// 實(shí)際的代碼中你應該這樣使用返回對象
// echo $e->getMessage();
}
?>
過(guò)程化風(fēng)格
<?php
$date = date_create('asdfasdf');
print_r(date_get_last_errors());
?>
以上例程會(huì )輸出:
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 ) )
返回數組中的索引 6 和 0 表示在解析過(guò)程中,所提供的日期時(shí)間字符串中無(wú)法正確解析的字符位置。