Opened 5 months ago
Last modified 5 months ago
#61468 new defect (bug)
DivisionByZero issue for comments on PHP8.0+
Reported by: | hideandgeek404 | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | major | Version: | |
Component: | Comments | Keywords: | has-patch dev-feedback |
Focuses: | Cc: |
Description
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
- Set the site's PHP version to 8.0+
- Visit
Settings > Discussion
and set theBreak comments into pages with x
option to 0. - Save changes
- Visit a blog post with comments active
- 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
.
Change History (5)
This ticket was mentioned in PR #6862 on WordPress/wordpress-develop by @Presskopp.
5 months ago
#1
- Keywords has-patch added
This ticket was mentioned in PR #6863 on WordPress/wordpress-develop by @narenin.
5 months ago
#2
Trac ticket: https://core.trac.wordpress.org/ticket/61468
In my opinion it makes to sense to be able to set the minimum comments per page to zero, while having the pagination option enabled.
Trac ticket: #61468