(PHP 5 >= 5.5.0, PHP 7, PHP 8)
DateTimeImmutable::getLastErrors — 警告およびエラーを返す
この関数にはパラメータはありません。
警告やエラーに関する情報を含む配列を返します。 警告やエラーがない場合は false
を返します。
バージョン | 説明 |
---|---|
8.2.0 | PHP 8.2.0 より前のバージョンでは、 この関数は警告やエラーがない場合でも false を返しませんでした。 代わりに、例に示している、警告やエラーに関する情報を含む配列を常に返していました。 |
例1 DateTimeImmutable::getLastErrors() の例
<?php
try {
$date = new DateTimeImmutable('asdfasdf');
} catch (Exception $e) {
// 使用例を出したかっただけ...
print_r(DateTimeImmutable::getLastErrors());
// オブジェクト指向流にやるなら、本来は以下のように書くべき
上の例の出力は以下となります。
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 は、エラーが発生した文字列内での文字の位置を表します。