From 56dc2bd916ced87f98cecdec774dd340286c1a61 Mon Sep 17 00:00:00 2001 From: Jens Kubieziel Date: Thu, 16 Apr 2026 09:31:57 +0000 Subject: [PATCH 1/2] Update comments.inc.php for compatibility with PHP 8.3 When you want to access all comments, S9Y runs into an HTTP 500: `PHP Fatal error: Uncaught DivisionByZeroError: Division by zero` in line 260. The comparison of strings and integers has changed in PHP 8. See https://www.php.net/manual/en/migration80.incompatible.php Previously the comparison in line 260 was `0 == 'all'` -> true. Whith the changes the comparison now is `0 == 'all'` -> false. Which leads to the above mentioned error message. I changed the code in a way that `$commentsPerPage` has either an interger or`COMMENTS_FILTER_ALL` as value and the comparison now checks type and value. So in the case of all comments the comparison is `'all' === 'all` -> true. This should fix the code. --- include/admin/comments.inc.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/include/admin/comments.inc.php b/include/admin/comments.inc.php index 7e4fd5198..d9716d585 100644 --- a/include/admin/comments.inc.php +++ b/include/admin/comments.inc.php @@ -6,7 +6,11 @@ $data = array(); -$commentsPerPage = (int)(!empty($serendipity['GET']['filter']['perpage']) ? $serendipity['GET']['filter']['perpage'] : 10); +$commentsPerPage = !empty($serendipity['GET']['filter']['perpage']) ? $serendipity['GET']['filter']['perpage'] : 10; +if ($commentsPerPage != COMMENTS_FILTER_ALL) { + $commentsPerPage = (int)($commentsPerPage); +} + $summaryLength = 200; $errormsg = array(); @@ -257,7 +261,7 @@ $sql = serendipity_db_query("SELECT COUNT(*) AS total FROM {$serendipity['dbPrefix']}comments c WHERE 1 = 1 " . ($c_type !== null ? " AND c.type = '$c_type' " : '') . $and, true); $totalComments = $sql['total']; -$pages = ($commentsPerPage == COMMENTS_FILTER_ALL ? 1 : ceil($totalComments/(int)$commentsPerPage)); +$pages = ($commentsPerPage === COMMENTS_FILTER_ALL ? 1 : ceil($totalComments/(int)$commentsPerPage)); if (isset($serendipity['GET']['page'])) { $page = (int)$serendipity['GET']['page']; } else { @@ -271,7 +275,7 @@ $linkNext = 'serendipity_admin.php?serendipity[adminModule]=comments&serendipity[page]='. ($page+1) . $searchString; $filter_vals = array(10, 20, 50, COMMENTS_FILTER_ALL); -if ($commentsPerPage == COMMENTS_FILTER_ALL) { +if ($commentsPerPage === COMMENTS_FILTER_ALL) { $limit = ''; } else { $limit = serendipity_db_limit_sql(serendipity_db_limit(($page-1)*(int)$commentsPerPage, (int)$commentsPerPage)); From 29c3b86f1dc4fcb07a0106eb170f516b968392ba Mon Sep 17 00:00:00 2001 From: onli Date: Tue, 28 Apr 2026 20:29:36 +0200 Subject: [PATCH 2/2] document changes --- docs/NEWS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/NEWS b/docs/NEWS index 84089b139..d8ade0596 100644 --- a/docs/NEWS +++ b/docs/NEWS @@ -1,6 +1,9 @@ Version 2.7-alpha1 () ------------------------------------------------------------------------ + * Fix division by zero error when accessing all PHP comments on PHP 8 + (thanks to @qbi) + Version 2.6.0 (April 10th, 2026) ------------------------------------------------------------------------