Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#41484 closed defect (bug) (fixed)

PHP 7.1 error in wp_star_rating()

Reported by: afragen's profile afragen Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 4.9 Priority: normal
Severity: normal Version: 4.9
Component: Plugins Keywords: has-patch needs-testing
Focuses: administration Cc:

Description

In PHP 7.1, passing a null or empty value to round() results in a PHP warning on the Add Plugin page. This happens when the star rating is 0.

This from line 2121 from /wp-admin/includes/template.php .

Attachments (1)

41484.diff (987 bytes) - added by afragen 8 years ago.

Download all attachments as: .zip

Change History (5)

@afragen
8 years ago

#1 @afragen
8 years ago

  • Keywords has-patch needs-testing dev-feedback added

#2 @SergeyBiryukov
8 years ago

  • Component changed from Upgrade/Install to Plugins
  • Focuses administration added
  • Milestone changed from Awaiting Review to 4.9

#3 @SergeyBiryukov
8 years ago

  • Keywords dev-feedback removed

Apparently $rating can be a float (0..5 in .5 increments) if $r['type'] is rating. Core only uses percent type, but float usage should also be documented.

I could not reproduce the actual warning with '0' as $r['rating']. Reproduced with '', but the API seems to return the former. Seems like a good fix anyway.

#4 @SergeyBiryukov
8 years ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 41184:

Plugins: In wp_star_rating(), use explicit type casting for $rating to avoid a "non-numeric value encountered" warning in PHP 7.1.

Clarify in the function DocBlock that $rating can be a float.

Props afragen.
Fixes #41484.

Note: See TracTickets for help on using tickets.