[wp-trac] [WordPress Trac] #61468: DivisionByZero issue for comments on PHP8.0+
WordPress Trac
noreply at wordpress.org
Wed Jun 19 14:39:33 UTC 2024
#61468: DivisionByZero issue for comments on PHP8.0+
----------------------------+-----------------------------
Reporter: hideandgeek404 | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Comments | Version: trunk
Severity: major | Keywords:
Focuses: |
----------------------------+-----------------------------
=== Quick summary
I have found an issue with PHP 8.0+ where if the `comments_per_page`
option is set to 0, which really shouldn't be possible, PHP 8.0+ fires a
DivisionByZero exception. This means that any blog post with the comments
section and form showing then hits a fatal error.
=== Steps to reproduce
1. Set the site's PHP version to 8.0+
2. Visit `Settings > Discussion` and set the `Break comments into pages
with x` option to 0.
3. Save changes
4. Visit a blog post with comments active
5. See the blank post and fatal error in the logs
=== A clear and concise description of what you expected to happen.
The blog post should load and show any existing comments above the comment
form.
=== What actually happened
When comments are activated on blog posts, loading the blog post in the
front end causes a blank screen and a fatal error in the logs.
{{{
PHP Fatal error: Uncaught DivisionByZeroError: Division by zero in
/wordpress/core/6.5.4/wp-includes/comment-template.php:1520
}}}
In `wp-includes/comment-template.php` on line 1520 we find this code:
{{{
$comment_args['offset'] = ( (int) ceil( $top_level_count / $per_page ) - 1
) * $per_page;
}}}
If the `comments_per_page` option is always going to be used for this
math, it should not be possible to set it to zero in `Settings >
Discussion`.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/61468>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list