Make WordPress Core

Opened 18 months ago

Closed 12 months ago

Last modified 12 months ago

#60364 closed defect (bug) (fixed)

Incorrect argument type given on number_format

Reported by: krishneup's profile krishneup Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 6.7 Priority: normal
Severity: normal Version:
Component: Site Health Keywords: has-patch
Focuses: Cc:

Description (last modified by sabernhardt)

Argument #1 ($num) must be of type float, string given in /var/www/src/wp-admin/includes/class-wp-debug-data.php:587

Change History (10)

#1 follow-up: @audrasjb
18 months ago

Hello, welcome to WordPress Core Trac and thank you for opening this ticket,

Could you please specify the exact function where the issue is located?
L587 doesn't correspond to your issue: https://github.com/WordPress/wordpress-develop/blob/trunk/src/wp-admin/includes/class-wp-debug-data.php#L587

Thanks

#2 @krishneup
18 months ago

Sorry for the wrong line number.

here's the MR link - https://github.com/WordPress/wordpress-develop/pull/5960

#3 in reply to: ↑ 1 ; follow-up: @krishneup
18 months ago

Replying to audrasjb:

Hello, welcome to WordPress Core Trac and thank you for opening this ticket,

Could you please specify the exact function where the issue is located?
L587 doesn't correspond to your issue: https://github.com/WordPress/wordpress-develop/blob/trunk/src/wp-admin/includes/class-wp-debug-data.php#L587

Thanks

Now I understand why my PR wasn't linked here. I am sorry for troubling you, it seems my github account has a bug, which I probably need to report with Github support team.

These were my changes: https://ibb.co/59HWPjJ
Unfortunately, you may not able to see my MR.

#4 @sabernhardt
18 months ago

  • Description modified (diff)

The PR proposes to run floatval() within number_format() on line 585:
'value' => number_format( floatval( $max_file_uploads ) ),

  1. Should this test use number_format_i18n() instead of number_format()?
  2. Could it use (float) instead of floatval()?
  3. Would it be better to assign the type when setting the variable?
    $max_file_uploads = (float) ini_get( 'max_file_uploads' );

The test was added in [48535].

#5 @SergeyBiryukov
12 months ago

  • Milestone changed from Awaiting Review to 6.7

Hi there, welcome to WordPress Trac! Thanks for the ticket.

I was able to reproduce the issue with the strict_types PHP setting turned on.

Since the goal of the Site Health Info screen is to display raw values where possible, I believe we can just remove the number_format() call here, as the other values in the same section, e.g. file_uploads, post_max_size, or upload_max_filesize are displayed as is.

#6 @SergeyBiryukov
12 months ago

  • Owner set to SergeyBiryukov
  • Status changed from new to accepted

This ticket was mentioned in PR #5960 on WordPress/wordpress-develop by krishneup.


12 months ago
#7

Error:

number_format(): Argument 1 ($num) must be of type float, string given in /var/www/src/wp-admin/includes/class-wp-debug-data.php

Few things:

  1. ini_get returns string data type .
  2. number_format expects first argument to be float number, but here string is provided.

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

#8 in reply to: ↑ 3 @SergeyBiryukov
12 months ago

Replying to krishneup:

Now I understand why my PR wasn't linked here. I am sorry for troubling you, it seems my github account has a bug, which I probably need to report with Github support team.

It appears that the PR was not linked because the Trac ticket link used the GitHub markdown formatting:

Trac ticket: [https://core.trac.wordpress.org/ticket/60364](https://core.trac.wordpress.org/ticket/60364)

I've updated it to a plain URL:

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

and the PR is properly linked here now.

#9 @SergeyBiryukov
12 months ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 58847:

Site Health: Display raw value for max_file_uploads on Site Health Info screen.

This resolves a fatal error if strict_types PHP setting is enabled:

Argument #1 ($num) must be of type float, string given

Since the goal of the Site Health Info screen is to display raw values where possible, the number_format() call here does not seem to provide any benefit.

Props krishneup, sabernhardt, audrasjb, SergeyBiryukov.
Fixes #60364.

@SergeyBiryukov commented on PR #5960:


12 months ago
#10

Thanks for the PR! Merged in r58847.

Note: See TracTickets for help on using tickets.