Klaus' Log

Do 04 Februar 2021

Wordpress plugin "count-per-day" is not compatible with PHP 8 and gives critical error

Posted by Klaus Eisentraut in howto   

Recently, the homepage of the "Blaskapelle Hohenpoelz" broke down and only displayed the error "There has been a critical error on your website.".

A quick look into the lighttpd error.log file gave the following reason:

PHP Fatal error:  Array and string offset access syntax with curly braces is no longer supported in [...snip...]/blaskapelle.hohenpoelz.de/wp-content/plugins/count-per-day/counter-core.php on line 151

Unfortunately, the Count per Day-Plugin does not seem to be PHP8 compatible. Recently, Arch Linux upgraded PHP to version 8 and this was the root cause for this issue. Here are the lines from the /var/log/pacman/pacman.log file:

[2021-02-01T20:16:03+0100] [ALPM] upgraded php (7.4.14-1 -> 8.0.1-1)
[2021-02-01T20:16:03+0100] [ALPM] upgraded php-fpm (7.4.14-1 -> 8.0.1-1)

I am not sure if this Wordpress-Plugin is still actively supported. If the deprecated curly braces syntax is the only PHP 8 incompatibility, this should be easy to fix by the count-per-day author. As a workaround for now, I simply downgraded back to PHP 7.4.14 with pacman -U /var/cache/pacman/pkg/php-7.4.14-1-x86_64.pkg.tar.zst /var/cache/pacman/pkg/php-fpm-7.4.14-1-x86_64.pkg.tar.zst. Additionally, I added php and php-fpm to the IgnorePkg option in /etc/pacman.conf. Please be aware that this prevents any updates from PHP from now on, so it should not be used as a permanent solution. I have contacted the author of the count-per-day plugin and if he pushes an update soon, I will migrate to PHP 8. If there will be no update, I most likely will remove the plugin completly.

UPDATE on 2020-03-01: The fix was trivial. I changed a single occurrence of curly braces in wp-content/plugins/count-per-day/counter-core.php, function getBytes. It was $last = strtolower($val{strlen($val)-1}); and I had to change it to $last = strtolower($val[strlen($val)-1]);. Now the plugin is PHP8 compatible. Unfortunately, this plugin was removed from Wordpress completly, so it will not get updates anymore. It is therefore a security risk, but at least I could upgrade to PHP8 for now.