Skip to content

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

Closed
wants to merge 1 commit into from

Conversation

derickr
Copy link
Member

@derickr derickr commented May 5, 2022

No description provided.

@derickr derickr requested review from iluuu1994, cmb69 and Girgias May 5, 2022 15:37
@derickr derickr self-assigned this May 5, 2022
@derickr derickr changed the title GH-8458: DateInterval::createFromDateString does not throw non-relative items are present GH-8458: DateInterval::createFromDateString does not throw if non-relative items are present May 5, 2022
Copy link
Member

@iluuu1994 iluuu1994 left a 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 👍

Copy link
Member

@cmb69 cmb69 left a 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()).

@derickr
Copy link
Member Author

derickr commented May 5, 2022

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.
What do you think?

@cmb69
Copy link
Member

cmb69 commented May 5, 2022

In a perfect world, I would throw a ValueError in all these cases (possibly not for the procedural APIs). But I'm somewhat concerned about the BC break (as I understand it, so far parts of the strings may have been ignored, but there still may have been a valid/usable DateInterval).

@Girgias
Copy link
Member

Girgias commented May 5, 2022

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?

@derickr derickr marked this pull request as draft May 6, 2022 09:40
@derickr derickr force-pushed the GH-8458-warning-non-relative branch from fbe218d to 684ddd3 Compare May 9, 2022 16:41
@derickr
Copy link
Member Author

derickr commented May 9, 2022

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.

@derickr derickr requested a review from cmb69 May 9, 2022 16:42
Copy link
Member

@cmb69 cmb69 left a 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)

@cmb69 cmb69 marked this pull request as ready for review May 10, 2022 18:04
derickr added a commit that referenced this pull request May 11, 2022
@derickr derickr closed this May 11, 2022
@derickr derickr deleted the GH-8458-warning-non-relative branch May 11, 2022 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants