mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-15 08:28:54 +00:00
Fixed bug #80694: DateTimeImmutable::createFromFormat not return false in all cases
This commit is contained in:
parent
532a253c43
commit
0aba3ea811
1 changed files with 41 additions and 0 deletions
|
@ -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">
|
||||
|
|
Loading…
Reference in a new issue