Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Component] [Validator] Support for DateTimeImmutable #18752

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
Closed

[Component] [Validator] Support for DateTimeImmutable #18752

wants to merge 1 commit into from

Conversation

krzysiekpiasecki
Copy link
Contributor

Q A
Branch? 2.7
Bug fix? no
New feature? yes/no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets n/a
License MIT
Doc PR n/a

When validating with DateTime constraint UnexpectedTypeException is thrown for DateTimeImmutable instances.

  • DateTimeImmutable behaves like a DateTime. Both implements the same interface DateTimeInterface.
  • DateTimeInterface cannot be implemented by the client.

@francisbesset
Copy link
Contributor

@stloyd says (#18749):

This wrong cause that interface was introduced in PHP 5.5, but Symfony < 3.0 supports PHP 5.3!

@stof
Copy link
Member

stof commented May 11, 2016

and this is also missing tests covering the case of DateTimeImmutable (skipping them on older PHP versions)

@francisbesset
Copy link
Contributor

@krzysiekpiasecki But if you need tu use DateTimeImmutable, you can use this trick:

if (null === $value || '' === $value || $value instanceof \DateTime || $value instanceof \DateTimeInterface) {
}

@krzysiekpiasecki
Copy link
Contributor Author

krzysiekpiasecki commented May 12, 2016

@francisbesset francisbesset What's the trick?

@francisbesset
Copy link
Contributor

The trick it is to keep the instanceof \DateTime and another check if the $value is an instance of \DateTimeInterface.
If PHP < 5.5.0 then the DateTimeInterface does not exists but PHP does not throw an error.

nicolas-grekas added a commit that referenced this pull request May 19, 2016
This PR was squashed before being merged into the 3.0 branch (closes #18759).

Discussion
----------

[Validator] Support for DateTimeImmutable

| Q             | A
| ------------- | ---
| Branch?       | 3.0
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #18752
| License       | MIT
| Doc PR        |

When validating with DateTime constraint UnexpectedTypeException is thrown for DateTimeImmutable instances.

Why PR?
- DateTimeImmutable behaves like a DateTime. Both implements the same interface DateTimeInterface.
- DateTimeInterface cannot be implemented by the client.

Commits
-------

f49659f [Validator] Support for DateTimeImmutable
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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.