Skip to content

Fix PeriodAbstract constructor when DateTimeImmutable instances are passed#12

Open
mpdude wants to merge 1 commit into
peter279k:masterfrom
mpdude:patch-1
Open

Fix PeriodAbstract constructor when DateTimeImmutable instances are passed#12
mpdude wants to merge 1 commit into
peter279k:masterfrom
mpdude:patch-1

Conversation

@mpdude
Copy link
Copy Markdown

@mpdude mpdude commented May 7, 2024

When DateTimeImmutable instances are used, the $this->end->add(...) call will not modify $this->end. It does not matter that a clone is used.

@mpdude
Copy link
Copy Markdown
Author

mpdude commented May 7, 2024

Probably the issue is much bigger, potentially all places that clone ...$someDate before using it made the false assumption that this will work for DateTimeImmutable instances.

@peter279k
Copy link
Copy Markdown
Owner

peter279k commented May 7, 2024

According to the official PHP site, the DateTime::createFromInterface method is only available since the PHP 8.0 version.

And this PR will be broken in PHP 7.x versions.

@mpdude
Copy link
Copy Markdown
Author

mpdude commented May 8, 2024

Any suggestion how this could be worked around?

@peter279k
Copy link
Copy Markdown
Owner

To resolve this issue, I've two suggestions:

  1. Using the method_exists to check whether the DateTime::createFromInterface is available. If not, using the original method call.
  2. Dropping PHP 7.x versions support for next released version.

Do you have any other recommendations about this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants