Update comments.inc.php for compatibility with PHP 8.3#968
Update comments.inc.php for compatibility with PHP 8.3#968qbi wants to merge 3 commits intos9y:masterfrom
Conversation
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.
|
|
||
| $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) { |
There was a problem hiding this comment.
Thank you, good catch and good fix!
My suggestion would be to change the first section as follows.
This introduces a stricter (type-safe) check against COMMENTS_FILTER_ALL.
if ($commentsPerPage !== COMMENTS_FILTER_ALL) {
$commentsPerPage = (int)$commentsPerPage;
}What do you think?
|
Surprisingly complicated code, originally. I assume it was never intended to rely on Alternative fix would be to always cast COMMENTS_FILTER_ALL when used in the comparison, so also on line 260 and 274, like Then this becomes a Not sure that's better, but wanted to understand the bug and have this shared :) |
|
I prepared the NEWS entry for this change. @qbi, please let us know if this is the way you want to be credited, or under your full name? If you could add @mattsches suggestion this would be great, otherwise I'll merge this as is the next days. In any case, thanks for finding and fixing this bug. |
When you want to access all comments, S9Y runs into an HTTP 500:
PHP Fatal error: Uncaught DivisionByZeroError: Division by zeroin 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 is0 == 'all'-> false. Which leads to the above mentioned error message.I changed the code in a way that
$commentsPerPagehas either an interger orCOMMENTS_FILTER_ALLas 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.