-
Notifications
You must be signed in to change notification settings - Fork 7.9k
GH-8458: DateInterval::createFromDateString does not throw if non-relative items are present #8500
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a nice improvement 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if we should throw here; if the format is unknown or bad, we raise E_WARNING
, so maybe we should do it here as well. But if we throw, we should consider to throw a ValueError
(zend_value_error()
).
I would argue that we should throw in the other case as well really, as you're not getting a usable object. But I now realise that this is both a procedural API (date_interval_create_from_string()) and an OO one (DateInterval::createFromString). I reckon we should warn for the procedural API, but throw in the OO variant. |
In a perfect world, I would throw a |
IIRC when I was doing the large chunk of warning to error promotion the general guideline which we had with @nikic was that if it is a programming error or relatively easy to check it should throw an error, otherwise it's kept as a warning. Mainly as the string my be provided from a user and not within the control of the dev. Although, I do think ideally if this was a new function/method it should be a ValueError but like @cmb69 said I wonder about the potential BC, but then I have a PR which fixes a bug which also goes from no warning to TypeError soooo Aside, could you add a test for the procedural version? |
…ative items are present
fbe218d
to
684ddd3
Compare
I've just pushed an update to this, and it will now always throw a warning, and not an exception. Although you can argue that there is a BC break, because FALSE is now returned if the date string is broken, at least it is now not silently ignoring a programming mistake. I also added a test case for the procedural variant. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this BC break is acceptable for a new minor version. Others might disagree, though.
(consider to change the NEWS entry; the method still doesn't throw in this case)
No description provided.