PHP Warning: Division by zero in …/scrolling-pagination-functions.php
-
Hi,
I’m getting this warning on my logs:
PHP Warning: Division by zero in /[full path to my WP installation]/wp-content/plugins/page-links-single-page-option/addons/scrolling-pagination/scrolling-pagination-functions.php on line 47
The affected function is
generate_scrolling_pagination()
and on line 47 we have:$scrolls = $pages / $pages_per_scroll;
By some reason, in my setup, sometimes
$pages_per_scroll
is zero, and so this naturally fails.A very quick & dirty fix is to simply change the above line to:
$scrolls = $pages / ($pages_per_scroll ?: 1);
but I guess there might be ‘cleaner’ ways to check why
$pages_per_scroll
is zero in some cases. I have to admit that your code is very clean and simple to read, but it would require me a lot of time to fully debug it.In the meantime, if readers of this forum see the above message on their web server logs, as said, the quick & dirty fix will at least get rid of the message and do something sensible.
As a reference, my setup runs on Ubuntu 16.04.6, nginx/1.16.1 + php-fpm 7.4.4, WordPress is at the latest version, running the Customizr Pro theme, and major plugins are Jetpack, WordFence, and WP Fastest Cache (there are plenty of minor plugins as well, including a few of my own…). PHP 7.4+ is a bit stricter on a lot of functions, and it may be the reason why this warning started popping up, although it could also be a ‘bad’ interaction with the latest version of the Customizr Pro theme.
- The topic ‘PHP Warning: Division by zero in …/scrolling-pagination-functions.php’ is closed to new replies.