<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.datetimeimmutable.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'ja',
  ),
  'this' => 
  array (
    0 => 'datetimeimmutable.getlasterrors.php',
    1 => 'DateTimeImmutable::getLastErrors',
    2 => '警告およびエラーを返す',
  ),
  'up' => 
  array (
    0 => 'class.datetimeimmutable.php',
    1 => 'DateTimeImmutable',
  ),
  'prev' => 
  array (
    0 => 'datetimeimmutable.createfrommutable.php',
    1 => 'DateTimeImmutable::createFromMutable',
  ),
  'next' => 
  array (
    0 => 'datetimeimmutable.modify.php',
    1 => 'DateTimeImmutable::modify',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'ja',
    'path' => 'reference/datetime/datetimeimmutable/getlasterrors.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="datetimeimmutable.getlasterrors" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">DateTimeImmutable::getLastErrors</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.5.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">DateTimeImmutable::getLastErrors</span> &mdash; <span class="dc-title">警告およびエラーを返す</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-datetimeimmutable.getlasterrors-description">
  <h3 class="title">説明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="modifier">static</span> <span class="methodname"><strong>DateTimeImmutable::getLastErrors</strong></span>(): <span class="type"><span class="type"><a href="language.types.array.php" class="type array">array</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   日付/時刻文字列のパース時に見つかった警告やエラーの配列を返します。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-datetimeimmutable.getlasterrors-parameters">
  <h3 class="title">パラメータ</h3>
  <p class="para">この関数にはパラメータはありません。</p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-datetimeimmutable.getlasterrors-returnvalues">
  <h3 class="title">戻り値</h3>
  <p class="para">
   警告やエラーに関する情報を含む配列を返します。
   警告やエラーがない場合は <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> を返します。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-datetimeimmutable.getlasterrors-changelog">
  <h3 class="title">変更履歴</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>バージョン</th>
       <th>説明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>8.2.0</td>
       <td>
        PHP 8.2.0 より前のバージョンでは、
        この関数は警告やエラーがない場合でも <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> を返しませんでした。
        代わりに、例に示している、警告やエラーに関する情報を含む配列を常に返していました。
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-datetimeimmutable.getlasterrors-examples">
  <h3 class="title">例</h3>
  <div class="example" id="example-1">
   <p><strong>例1 <span class="function"><strong>DateTimeImmutable::getLastErrors()</strong></span> の例</strong></p>
   <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">try {<br />    </span><span style="color: #0000BB">$date </span><span style="color: #007700">= new </span><span style="color: #0000BB">DateTimeImmutable</span><span style="color: #007700">(</span><span style="color: #DD0000">'asdfasdf'</span><span style="color: #007700">);<br />} catch (</span><span style="color: #0000BB">Exception $e</span><span style="color: #007700">) {<br />    </span><span style="color: #FF8000">// 使用例を出したかっただけ...<br />    </span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">DateTimeImmutable</span><span style="color: #007700">::</span><span style="color: #0000BB">getLastErrors</span><span style="color: #007700">());<br /><br />    </span><span style="color: #FF8000">// オブジェクト指向流にやるなら、本来は以下のように書くべき<br />    </span><span style="color: #007700">echo </span><span style="color: #0000BB">$e</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getMessage</span><span style="color: #007700">();<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>上の例の出力は以下となります。</p></div>
   <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">Array
(
    [warning_count] =&gt; 1
    [warnings] =&gt; Array
        (
            [6] =&gt; Double timezone specification
        )

    [error_count] =&gt; 1
    [errors] =&gt; Array
        (
            [0] =&gt; The timezone could not be found in the database
        )
)
Failed to parse time string (asdfasdf) at position 0 (a): The timezone could not be found in the database</pre>
</div>
   </div>
   <div class="example-contents"><p>
    この出力のインデックス 6 と 0 は、エラーが発生した文字列内での文字の位置を表します。
   </p></div>
  </div>
  <div class="example" id="example-2">
   <p><strong>例2 繰り上がった日付を検知する</strong></p>
   <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$date </span><span style="color: #007700">= </span><span style="color: #0000BB">DateTimeImmutable</span><span style="color: #007700">::</span><span style="color: #0000BB">createFromFormat</span><span style="color: #007700">(</span><span style="color: #DD0000">'!Y-m-d'</span><span style="color: #007700">, </span><span style="color: #DD0000">'2020-02-30'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">DateTimeImmutable</span><span style="color: #007700">::</span><span style="color: #0000BB">getLastErrors</span><span style="color: #007700">());</span></span></code></div>
   </div>

   <div class="example-contents"><p>上の例の出力は以下となります。</p></div>
   <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">Array
(
    [warning_count] =&gt; 1
    [warnings] =&gt; Array
        (
            [10] =&gt; The parsed date was invalid
        )

    [error_count] =&gt; 0
    [errors] =&gt; Array
        (
        )
)</pre>
</div>
   </div>
  </div>
 </div>


</div><?php manual_footer($setup); ?>