Opened 12 months ago
Last modified 2 months ago
#61468 new defect (bug)
DivisionByZero issue for comments on PHP8.0+
Reported by: |
|
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 (10)
This ticket was mentioned in PR #6862 on WordPress/wordpress-develop by @Presskopp.
12 months ago
#1
- Keywords has-patch added
This ticket was mentioned in PR #6863 on WordPress/wordpress-develop by @narenin.
12 months ago
#2
Trac ticket: https://core.trac.wordpress.org/ticket/61468
#3
@
12 months ago
- Keywords dev-feedback added
Hi @hideandgeek404
In my opinion we can handle the case where $per_page
is 0 by adding a check to ensure that it doesn't perform any division by zero or other invalid operations. I have added patch that can handle this scenario.
#5
@
11 months ago
- Version trunk deleted
Removing trunk
as the Version that introduced this issue. Why? I'm not identifying any commits that happened during the current 6.6 or 6.7-alpha cycles. Once (or if) the commit is found, the Version should be updated.
#6
@
2 months ago
Hello,
is there any progress on this issue?
Is there a solution?
https://wordpress.org/support/topic/php-8-x-missing-sidebar-comments-template-and-footer/
#8
@
2 months ago
Thanks @Presskopp The codes are not compatible, I couldn't find it. The current (6.7.2) options-discussion.php file contains the following codes;
__( 'Hold a comment in the queue if it contains %s or more links. (A common characteristic of comment spam is a large number of hyperlinks.)' ), '<input name="comment_max_links" type="number" step="1" min="0" id="comment_max_links" value="' . esc_attr( get_option( 'comment_max_links' ) ) . '" class="small-text" />'
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