impress-org / givewp

GiveWP - The #1 Donation Plugin for WordPress. Easily accept donations and fundraise using your WordPress website.
https://givewp.com/
GNU General Public License v3.0
345 stars 191 forks source link

[PHP 8] Fatal error: Uncaught TypeError: round(): Argument #1 ($num) must be of type int|float, string given #6044

Closed flack closed 2 years ago

flack commented 3 years ago

User Story

As a developer, I want to show progress stats for forms

Details

I have the following code

$form = new Give_Donate_Form($id);
$stats = give_goal_progress_stats($form);

Expected Behavior

I get the $stats array with the data I'm looking form

Steps to Reproduce

If $form has no goal set, i.e. $form->goal is null, then the following fatal error is thrown in PHP 8:

TypeError: round(): Argument #1 ($num) must be of type int|float, string given in give/includes/misc-functions.php on line 1941

Additional Context

If I change this line:

https://github.com/impress-org/givewp/blob/1d802eefd48522df866240235b532a72183104d2/includes/class-give-donate-form.php#L93

to look like this:

    private $goal = 0.0;

Then the error goes away. I don't know if this is the correct fix though

System Information

Details ### Server Environment ### Hosting Provider: DBH: localhost, SRV: rfp TLS Connection: Verbindung verwendet TLS 1.3 TLS Connection: Probably Okay Server Info: Apache/2.4.48 (Ubuntu) PHP Version: 8.0.8 PHP Post Max Size: 8 MB PHP Time Limit: 30 PHP Max Input Vars: 1000 PHP Max Upload Size: 2 MB cURL Version: 7.74.0, OpenSSL/1.1.1l SUHOSIN Installed: – MySQL Version: 8.0.26 Default Timezone is UTC: ✔ fsockopen/cURL: ✔ SoapClient: ❌Dein Server hat die Klasse SoapClient nicht aktiviert - manche Gateway-Plugins, die SOAP benutzen, werden nicht wie erwartet funktionieren. DOMDocument: ✔ gzip: ✔ GD Graphics Library: ✔ Multibyte String: ✔ Remote Post: ✔ Remote Get: ✔

Acceptance Criteria

I really don't understand how this section is supposed to work..

flack commented 3 years ago

I've added this as a local workaround for now:

add_filter('give_get_set_goal', function ($goal) {
    return $goal ?: 0;
});
JasonTheAdams commented 2 years ago

Ah, that makes sense. I'm ok with setting the form property, but want to make sure a non-null value wouldn't cause issues elsewhere. @ravinderk, what do you think?

ravinderk commented 2 years ago

Ah, that makes sense. I'm ok with setting the form property but want to make sure a non-null value wouldn't cause issues elsewhere. @ravinderk, what do you think?

@JasonTheAdams we use the goal process in frontend and backend. I will review the issue with PHP 8.0.

canny[bot] commented 2 years ago

This issue has been linked to a Canny post: Using PHP 8 with Currency Switcher and Fee Recovery activated, Recount Stats Throws a Critical Error. :tada:

canny[bot] commented 2 years ago

This issue has been unlinked from a Canny post: Using PHP 8 with Currency Switcher and Fee Recovery activated, Recount Stats Throws a Critical Error. :cry:

ravinderk commented 2 years ago

Step to reproduce

  1. Enable goal for donation form
  2. Set _give_set_goal to 0 in form meta table