Fatal Error in Analytics Dashboard with Non-Numeric Data in PHP 8

#1056327
  • Resolved steveolst
    Rank Math free

    Hi Rank Math Support,

    We’ve identified a fatal error in the Analytics Dashboard of Rank Math when running on PHP 8. The issue occurs when the dashboard receives non-numeric data (such as “n/a”) from the analytics source. PHP 8 no longer allows functions like abs() to process strings, which leads to a fatal error if no validation is in place.

    The affected code behaves like:

    $total = abs($total_value); // $total_value may be "n/a"
    This worked in PHP 7 but breaks in PHP 8 due to stricter typing.

    Temporary Patch:
    We’ve applied the following patch in our staging environment to prevent the error:

    $total = abs((float) $total_value);
    This safely casts the value and avoids type-related crashes.

    Would it be possible to address this in a future plugin update? That way we can remove the patch and ensure stability after future updates.

    Thanks in advance for your help!

    Best regards,
    Steven

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello,

    We apologize for the issue you are facing with the fatal error in the Analytics Dashboard when using PHP 8. Thank you for bringing this to our attention and for providing a temporary patch that you’ve implemented.

    Your feedback regarding the handling of non-numeric data in PHP 8 is valuable, and we appreciate your suggestion for a more robust solution in future updates. We will ensure that this concern is communicated to our development team for consideration in upcoming releases.

    In the meantime, if you encounter any further issues or need assistance, please feel free to reply to this ticket, and a human agent from our support team will assist you further.

    Thank you for your understanding and patience!

    Sources:
    Fatal Error Happening on Some Installations After 1.0.49 Update » Rank Math

    This seems like a different error than our:
    Fatal error: Uncaught RuntimeException: Error saving action: Error saving action: Table ‘dbname.prefix_wp8o_actionscheduler_actions’ doesn’t exist in /…/wp-content/plugins/action-scheduler/classes/migration/ActionScheduler_DBStoreMigrator.php:44

    This is our error:
    2025-06-24T19:28:04+00:00 Critical Uncaught TypeError: abs(): Argument #1 ($num) must be of type int|float, string given in /home/1109913.cloudwaysapps.com/tynddtvvzn/public_html/wp-content/plugins/seo-by-rank-math/includes/modules/analytics/class-analytics-common.php:338

    Hello,

    Thank you for contacting Rank Math support.

    We have found the cause and are working on a fix, but before then, you may patch this by changing the file seo-by-rank-math/includes/modules/analytics/class-analytics-common.php lines 339 and 340

    from:

    $difference = isset( $item['difference'] ) ? abs( $item['difference'] ) : 0;
    $is_negative = isset( $item['difference'] ) && abs( $item['difference'] ) !== $item['difference'];

    to:

    $difference = isset( $item['difference'] ) && 'n/a' !== $item['difference'] ? abs( $item['difference'] ) : 0;
    $is_negative = isset( $item['difference'] ) && 'n/a' !== $item['difference'] && abs( $item['difference'] ) !== $item['difference'];

    We apologize for any inconveniences that might have been caused as a result of this issue.

    Please do not hesitate to let us know if you need our assistance with anything else.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)

The ticket ‘Fatal Error in Analytics Dashboard with Non-Numeric Data in PHP 8’ is closed to new replies.