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 deprecation for PHP 8.1 #3449

Merged
merged 1 commit into from
Nov 1, 2021

Conversation

andypost
Copy link
Contributor

@andypost andypost commented Oct 12, 2021

Closes #3448

With this fix I got clean reports

Steps https://3v4l.org/flZrS

@gsherwood gsherwood added this to Idea Bank in PHPCS v3 Development via automation Oct 12, 2021
@gsherwood gsherwood added this to the 3.6.2 milestone Oct 12, 2021
Copy link

@caugner caugner left a comment

Choose a reason for hiding this comment

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

LGTM, since $time > 1000, we're not interested in the decimals and can therefore safely cast $time to int, discarding those decimals.

Copy link
Contributor

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

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

Okay, finally had a chance to have a closer look, but this fix is incorrect as it doesn't fix anything.

Division with floats works perfectly fine without deprecation notice in PHP 8.1, this line (73) is not the "problem" line.

The actual problem is in line 67:

$secs = round((($time % 60000) / 1000), 2);

As per the PHP manual on arithmetic operators:

Operands of modulo are converted to int before processing. For floating-point modulo, see fmod().

And as fmod() has been available since PHP 4.2.0, it can safely be used to maintain the behaviour as it was previously.
Ref: https://www.php.net/manual/en/function.fmod.php

In other words, line 67 should be changed to the below to solve the actual problem:

$secs = round((fmod($time, 60000) / 1000), 2);

Also see:
https://3v4l.org/r3DZZ (without fix)
https://3v4l.org/9FelR (with correct fix)

@andypost
Copy link
Contributor Author

@jrfnl thank you for review, fixed feedback... it's strange how I mixed lines

@jrfnl
Copy link
Contributor

jrfnl commented Oct 31, 2021

@andypost No worries, happens to the best of us, but it does very much explain my confusion when I initially looked at the PR.

@gsherwood gsherwood merged commit 9e7aec1 into squizlabs:master Nov 1, 2021
gsherwood added a commit that referenced this pull request Nov 1, 2021
PHPCS v3 Development automation moved this from Idea Bank to Ready for Release Nov 1, 2021
@gsherwood
Copy link
Member

@jrfnl Thanks a lot for the review and guidance on the fix
@andypost Thanks for the bug report and PR

@andypost andypost deleted the 3448-deprecation-8.1 branch November 1, 2021 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
PHPCS v3 Development
Ready for Release
Development

Successfully merging this pull request may close these issues.

PHP 8.1 deprecation notice while generating running time value
4 participants