Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Form][Validator] Fix checking result of DateTime::getLastErrors #47428

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

Merged
merged 1 commit into from
Aug 30, 2022

Conversation

nicolas-grekas
Copy link
Member

Q A
Branch? 4.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets -
License MIT
Doc PR -

Spotted by our CI on PHP 8.2

This returns an array on PHP < 8.2 and false on 8.2:

DateTime::createFromFormat('Y', '2022');
var_dump(DateTime::getLastErrors());

/cc @derickr FYI as this might also be considered as a BC break on PHP 8.2

Copy link
Member

@xabbuh xabbuh 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 (at least) the DateTimeValidator needs some more changes

@stof
Copy link
Member

stof commented Aug 30, 2022

Access to $errors['warnings'] should indeed also be guarded there.

@derickr
Copy link

derickr commented Aug 30, 2022 via email

@stof
Copy link
Member

stof commented Aug 30, 2022

This is a bug fix as the new 8.2 behaviour is how it has been documented for over a decade. I didn't merge it to 8.0 and 8.1 because it does change BC.

Well, I would say that code is a lot more likely to expect the behavior that exists since a decade than the documented code that was never implemented until now.

@carsonbot carsonbot changed the title Fix checking result of DateTime::getLastErrors [Form][Validator] Fix checking result of DateTime::getLastErrors Aug 30, 2022
@nicolas-grekas
Copy link
Member Author

looks like (at least) the DateTimeValidator needs some more changes

yup, fixed

@nicolas-grekas nicolas-grekas merged commit cfc492e into symfony:4.4 Aug 30, 2022
@nicolas-grekas nicolas-grekas deleted the date-errors branch August 31, 2022 09:14
@PhilETaylor
Copy link
Contributor

I just stumbled upon this bug in my project, wrote the pr, unit test and was getting ready to submit and then checked my branch was up to date and it wasn't, so checked here and BANG 🎉 its already fixed 5 days ago... you guys are awesome!

fabpot added a commit to sensiolabs/SensioFrameworkExtraBundle that referenced this pull request Sep 5, 2022
This PR was squashed before being merged into the 6.1.x-dev branch.

Discussion
----------

PHP 8.2 Compatibility DateTime::getLastErrors

DateTime::getLastErrors() is documented as returning `array|false` https://www.php.net/manual/en/datetime.getlasterrors.php

As discussed here symfony/symfony#47428 (comment)

`@derickr` quoted as saying
"This is a bug fix as the new 8.2 behaviour is how it has been documented for over a decade."

Commits
-------

00f08ea PHP 8.2 Compatibility DateTime::getLastErrors
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.

8 participants