Make WordPress Core

Opened 2 years ago

Closed 22 months ago

Last modified 22 months ago

#54996 closed defect (bug) (invalid)

PHP8.1 throw 'Deprecated' in WordPress 6.0-alpha-52650

Reported by: haozi's profile haozi Owned by:
Milestone: Priority: normal
Severity: trivial Version: 6.0
Component: I18N Keywords: php81
Focuses: administration Cc:

Description

In PHP8.1,Implicit incompatible float to int conversion is deprecated.

Because of it, wordpress will throw a PHP Deprecated in page footer like:

Deprecated:  Implicit conversion from float 0.009382247924804688 to int loses precision in /www/wwwroot/mysite/wp-includes/pomo/plural-forms.php

To fix it, I try to add (int) in /wp-includes/pomo/plural-forms.php on line 242-248 like:

                public function get( $num ) {
                        if ( isset( $this->cache[ (int) $num ] ) ) {
                                return $this->cache[ $num ];
                        }
                        $this->cache[ (int) $num ] = $this->execute( (int) $num );
                        return $this->cache[ (int) $num ];
                }

It works well!

Change History (20)

#1 @haozi
2 years ago

  • Summary changed from PHP8.1 Deprecated in WordPress 6.0-alpha-52650 to PHP8.1 throw 'Deprecated' in WordPress 6.0-alpha-52650

#2 @SergeyBiryukov
2 years ago

  • Component changed from General to I18N
  • Milestone changed from Awaiting Review to 6.0

#3 @SergeyBiryukov
2 years ago

  • Keywords php81 added

This ticket was mentioned in PR #2248 on WordPress/wordpress-develop by DevHaoZi.


2 years ago
#4

In PHP8.1,Implicit incompatible float to int conversion is deprecated.
Because of it, wordpress will throw a PHP Deprecated in page footer.

Trac ticket: https://core.trac.wordpress.org/ticket/54996

#5 @jrf
2 years ago

  • Keywords reporter-feedback added
  • Severity changed from major to trivial

@haozi Thanks for reporting this.

To be honest, I'd like to see a full backtrace of this notice as this is something which shouldn't be able to occur if the internationalization/translation functions are used correctly, so I'd like to get to the bottom of where this is coming from.

Adding an (int) cast, like you suggest in the GitHub PR, would be hiding the error, instead of fixing it at the source. This, IMO, is the wrong way to go.

This ticket was mentioned in Slack in #core by mike. View the logs.


2 years ago

#7 @costdev
2 years ago

  • Keywords needs-patch added; has-patch removed
  • Milestone changed from 6.0 to 6.1

This ticket was discussed in the recent bug scrub.

As this ticket has been awaiting reporter-feedback for a while now and it's late in the 6.0 cycle, I'm moving this to 6.1.

Those attending the scrub also agreed that the current patch ultimately hides the error and this needs more investigation. Adding needs-patch.

Props @mikeschroder

#8 @cadic
23 months ago

From https://www.gnu.org/software/gettext/manual/html_node/Plural-forms.html

Negative and floating-point values usually represent physical entities for which singular and plural don’t clearly apply. In such cases, there is no need to use ngettext; a simple gettext call with a form suitable for all values will do. For example:
printf (gettext ("Time elapsed: %.3f seconds"), num_milliseconds * 0.001);
Even if num_milliseconds happens to be a multiple of 1000, the output
Time elapsed: 1.000 seconds
is acceptable in English, and similarly for other languages.

This means using (int) to convert float to integer will break the logic and display 1.0 as singular number.

#9 follow-up: @bradleyt
22 months ago

I am seeing this on PHP 8.1.9, coming from this line in the Query Monitor plugin:

$text = _n( '%s S', '%s S', $db->total_time, 'query-monitor' );

#10 in reply to: ↑ 9 @jrf
22 months ago

Replying to bradleyt:

I am seeing this on PHP 8.1.9, coming from this line in the Query Monitor plugin:

$text = _n( '%s S', '%s S', $db->total_time, 'query-monitor' );

So, please submit a fix to the Query Monitor plugin. /cc @johnbillion

#11 @johnbillion
22 months ago

This was fixed recently in Query Monitor but I've not released a new version containing it yet.

#12 @jrf
22 months ago

Great to hear @johnbillion !

#13 @JeffPaul
22 months ago

@bradleyt if you use a development version of Query Monitor (at least until a new version is released), do you still see the error you noted?

#14 follow-up: @desrosj
22 months ago

  • Keywords close added
  • Milestone changed from 6.1 to Future Release

Returning to the original report. @haozi, have you been able to reproduce without any plugins active?

You didn't have the Query Monitor plugin active, by chance?

Marking as a close candidate, pending reporter feedback and since this doesn't have any actionable steps, punting to Future Release.

#15 in reply to: ↑ 14 @haozi
22 months ago

Replying to desrosj:

Returning to the original report. @haozi, have you been able to reproduce without any plugins active?

You didn't have the Query Monitor plugin active, by chance?

Marking as a close candidate, pending reporter feedback and since this doesn't have any actionable steps, punting to Future Release.

No. I think it's caused by Query Monitor old version.

#16 @haozi
22 months ago

  • Summary changed from PHP8.1 throw 'Deprecated' in WordPress 6.0-alpha-52650 to PHP8.1在WordPress 6.0-alpha-52650中抛出“不建议使用”

#17 @haozi
22 months ago

  • Keywords reporter-feedback needs-patch removed

#18 @haozi
22 months ago

  • Summary changed from PHP8.1在WordPress 6.0-alpha-52650中抛出“不建议使用” to PHP8.1 throw 'Deprecated' in WordPress 6.0-alpha-52650

#19 @haozi
22 months ago

  • Resolution set to wontfix
  • Status changed from new to closed

#20 @SergeyBiryukov
22 months ago

  • Keywords close removed
  • Milestone Future Release deleted
  • Resolution changed from wontfix to invalid

Thanks for the follow-up!

It appears that this is an issue with a particular plugin rather than WordPress core, changing the resolution accordingly.

Note: See TracTickets for help on using tickets.