<?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 => 'ru',
  ),
  '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' => 'ru',
    '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 /><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 />}</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 /><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); ?>