• Resolved Ivan Arnaudov

    (@ivanarnaudov)


    Hi Bowo,

    I got another bug report for you following SD release 2.1.0.

    This code fragment from admin/class-system-dashboard-admin.php breaks under PHP 8.0 and later with the following error message:

    [STDERR] PHP Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, string given in ..../wp-content/plugins/system-dashboard/admin/<strong>class-system-dashboard-admin.php:2549</strong>

    /**
    * Get # of rewrite rules
    *
    * @since 2.1.0
    */
    public function sd_rewrite_rules_count() {
    
      $rewrite_rules = get_option( 'rewrite_rules' );
    
      $output = count( $rewrite_rules );
    
      return $output;
    
    }

    The reason being that get_option( ‘rewrite_rules’ ) returns an empty result and

    8.0.0 count() will now throw TypeError on invalid countable types passed to the value parameter.

    Reference: PHP Manual

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Ivan Arnaudov

    (@ivanarnaudov)

    FWIF, sd_rewrite_rules() which operates on the same value, also breaks for the same reason (and leaves the dropdown list empty). So the underlying reason should be the way rewrite_rules are fetched?

    Note: I am testing this on a dev site with 1 static page of content and default permalinks. Might be simply there aren’t any rewrite_rules? Will check the DB and update this reply.

    Update: Yes, it turned out the rewrite_rules within wp_options can be empty. Hence the root cause for failure by sd_rewrite_rules() and sd_rewrite_rules_count().

    So the possible solution would be to gracefully handle the rare condition where there are zero rewrite rules.

    • This reply was modified 2 years, 11 months ago by Ivan Arnaudov. Reason: Updated with more info and possible solution
    Plugin Author Bowo

    (@qriouslad)

    As usual, thanks so much for finding and reporting the bug, and also getting deep into the root cause of it!

    I’m pushing v2.2.1 now that will hopefully fix this issue the way you have suggested. Let me know if it indeed resolves the issue.

    Thread Starter Ivan Arnaudov

    (@ivanarnaudov)

    Yes, thanks!! Marking issue as resolved.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Conflict using count() under PHP 8.x’ is closed to new replies.