# Remove warning when parsing datetime with + symbol?

- Thread: https://externals.io/message/119025
- Original archive: https://news-web.php.net/php.internals/119025
- Started by mickmackusa on 2022-11-24T08:25:03+00:00
- Messages: 5
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #119025 — mickmackusa — 2022-11-24T08:25:03+00:00

URL: https://externals.io/message/119025#119025

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

---

## #119045 — Derick Rethans — 2022-11-28T15:50:37+00:00

URL: https://externals.io/message/119025#119045 · In reply to: #119025

> 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()?

I have no idea why I decided that was a good idea back all these years, 
and I'm perfectly happy to remove that restriction from PHP 8.3 
forwards — it's too late to do that in PHP 8.2 now, as it's being 
released next week.

cheers,
Derick

-- 
PHP 7.4 Release Manager
Host of PHP Internals News: https://phpinternals.news
Like Xdebug? Consider supporting me: https://xdebug.org/support
https://derickrethans.nl | https://xdebug.org | https://dram.io
twitter: @derickr and @xdebug

---

## #119047 — Christoph M. Becker — 2022-11-28T16:31:55+00:00

URL: https://externals.io/message/119025#119047 · In reply to: #119045

> 
>
> > […]
>
> I have no idea why I decided that was a good idea back all these years,
> and I'm perfectly happy to remove that restriction from PHP 8.3
> forwards — it's too late to do that in PHP 8.2 now, as it's being
> released next week.

That would appear to consitute a BC break.  From the docs:

| If this format specifier is present, trailing data in the string will
| not cause an error, but a warning instead

This can be used to parse the date (without the +, parsing may fail),
but still be able to return a message about ignored characters to the user.

--
Christoph M. Becker

---

## #119048 — Paul Dragoonis — 2022-11-28T16:47:55+00:00

URL: https://externals.io/message/119025#119048 · In reply to: #119047

> 
>
> > […]
>
> That would appear to consitute a BC break.  From the docs:
>
> | If this format specifier is present, trailing data in the string will
> | not cause an error, but a warning instead
>
> This can be used to parse the date (without the +, parsing may fail),
> but still be able to return a message about ignored characters to the user.
>

We are allowed to break BC in minor version upgrades, Chris.

We can allow this is 8.3 I think, rather than waiting for 9.0

What do you think?



> --
> Christoph M. Becker
>
> --
> 
> To unsubscribe, visit: https://www.php.net/unsub.php

---

## #119074 — Derick Rethans — 2022-12-02T10:15:22+00:00

URL: https://externals.io/message/119025#119074 · In reply to: #119048

> 
> 
> > […]
> 
> We are allowed to break BC in minor version upgrades, Chris.
> 
> We can allow this is 8.3 I think, rather than waiting for 9.0
> 
> What do you think?

No, we don't break BC for minor gains. If Christopher says that this is 
a documented feature, then there is even less opportunity to do so.

I'll see if I can come up with a different letter to allow for just 
ignoring trailing data.

cheers,
Derick

-- 
https://derickrethans.nl | https://xdebug.org | https://dram.io

Author of Xdebug. Like it? Consider supporting me: https://xdebug.org/support
Host of PHP Internals News: https://phpinternals.news

mastodon: @derickr@phpc.social @xdebug@phpc.social
twitter: @derickr and @xdebug
