Skip to content
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

Fix error on PHP 8.4 #454

Merged
merged 3 commits into from
Jul 18, 2024
Merged

Fix error on PHP 8.4 #454

merged 3 commits into from
Jul 18, 2024

Conversation

ADmad
Copy link
Member

@ADmad ADmad commented Jul 13, 2024

PHP 8.4 adds a new interface method DatetimeImmutable::createFromTimestamp().

@ADmad ADmad force-pushed the php-8.4 branch 2 times, most recently from d6b91c0 to 7593c47 Compare July 13, 2024 13:43
@ADmad
Copy link
Member Author

ADmad commented Jul 13, 2024

The signature mismatch issue on PHP 8.4 is easily fixable but as seen from the failed tests the result of DateTimeImmutable::createFromTimestamp() is different than our implementation.

@ADmad ADmad force-pushed the php-8.4 branch 4 times, most recently from a7f078d to a1fcda1 Compare July 13, 2024 16:59
@ADmad ADmad marked this pull request as ready for review July 13, 2024 16:59
@ADmad
Copy link
Member Author

ADmad commented Jul 13, 2024

The change in behavior will need to be documented in the release notes. If $timezone is not explicitly passed then the instance has timezone set to +00:00 unlike earlier where the currently set default timezone was used.

@ADmad ADmad force-pushed the php-8.4 branch 2 times, most recently from 3f7a71b to ccfccdc Compare July 14, 2024 13:40
@ADmad ADmad added this to the 3.next milestone Jul 14, 2024
{
return static::now($timezone)->setTimestamp($timestamp);
$instance = PHP_VERSION_ID >= 80400 ? parent::createFromTimestamp($timestamp) : new static('@' . $timestamp);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we accept float, do we need to do any special rounding/etc to mimic the 8.4 behavior when converting to a @timestamp ?

I hope not. I assume they expect the timestamp to still be an integer in float format.

Copy link
Member Author

@ADmad ADmad Jul 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume they expect the timestamp to still be an integer in float format.

No, the fractional part of floats is used as microseconds https://3v4l.org/OT84B#v8.1.0
We don't have to do any additional processing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, ok. Wasn't sure if the @ format would throw an error, but I think that's ok if it does.

@markstory markstory merged commit 786d69e into 3.next Jul 18, 2024
6 checks passed
@markstory markstory deleted the php-8.4 branch July 18, 2024 03:18
@markstory
Copy link
Member

I started a draft release for 3.1 with the behavior change we've inherited from PHP.

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.

3 participants