Fixed bug #80694: DateTimeImmutable::createFromFormat not return false in all cases

This commit is contained in:
Derick Rethans 2022-06-04 17:53:29 +01:00
parent 532a253c43
commit 0aba3ea811

View file

@ -549,6 +549,47 @@ Sat, 04 Jun 2022 17:01:37 +0000
</listitem>
</orderedlist>
</example>
<para>
In order to detect overflows in dates, you can use the
<methodname>DateTimeInterface::getLastErrors</methodname> name, which will
include a warning if an overflow occured.
</para>
<example>
<title>Detecting overflown dates</title>
<programlisting role="php">
<![CDATA[
<?php
$d = DateTimeImmutable::createFromFormat('Y-m-d H:i:s', '2021-17-35 16:60:97');
echo $d->format(DateTimeImmutable::RFC2822), "\n\n";
var_dump(DateTimeImmutable::GetLastErrors());
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
Sat, 04 Jun 2022 17:01:37 +0000
array(4) {
'warning_count' =>
int(2)
'warnings' =>
array(1) {
[19] =>
string(27) "The parsed date was invalid"
}
'error_count' =>
int(0)
'errors' =>
array(0) {
}
}
]]>
</screen>
</example>
</refsect1>
<refsect1 role="seealso">