Remove warning when parsing datetime with + symbol?
| From: | mickmackusa | Date: | Thu, 24 Nov 2022 08:25:03 +0000 |
| Subject: | Remove warning when parsing datetime with + symbol? | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-119025@lists.php.net to get a copy of this message | ||
Can anyone explain to me why it is desirable/beneficial for the DateTime
class to store a warning that trailing characters were ignored while
parsing a date/time string with the + symbol in createFromFormat()?
Basic example: https://3v4l.org/Sod9o
$dt = DateTime::createFromFormat('h:i:A+', '01:31:PM - 03:00:PM');
var_export(DateTime::getLastErrors());
Output:
array ( 'warning_count' => 1, 'warnings' => array ( 8 => 'Trailing
data',
), 'error_count' => 0, 'errors' => array ( ), )
Docs:
https://www.php.net/manual/en/datetimeimmutable.createfromformat.php#:~:text=If%20this%20format,instead
I mean, why would I welcome the warning when I explicitly stated that I
want to ignore the trailing characters?
If there is longer a good reason for the warning, can it be removed from
the language?
If there is some benefit from having this feedback, then could it be moved
to be a new property of the datetime object?
To programming purists who hate generating notices and warnings, this
probably feels like a wart on the language.
Please enlighten me.
mickmackusa