Skip to content

PHP8: count(): Argument #1 ($value) must be of type Countable|array, bool given

Summary

With PHP 8.1, the above error prevents ISPconfig from loading. With PHP 7.4, this error does not occur.

Steps to reproduce

  • Setup an Ubuntu 22.04 minimal VM image and ssh into it
  • cd /tmp
  • git clone https://git.ispconfig.org/ispconfig/ispconfig-autoinstaller.git
  • cd ispconfig-autoinstaller
  • git checkout ubuntu-22 # for php8 support which ubuntu20.04 doesn't have yet
  • ./ispc3-ai.sh --channel=dev --use-ftp-ports=40110-40210 --unattended-upgrades=autoclean,reboot
  • reboot the VM

Then test ISPconfig. The header appears, but nothing else. In the apache error log, this error is shown:

mod_fcgid: stderr: PHP Fatal error:  Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, bool given in /usr/local/ispconfig/interface/lib/classes/tpl.inc.php(1366) : eval()'d code:116
mod_fcgid: stderr: Stack trace:
mod_fcgid: stderr: #0 /usr/local/ispconfig/interface/lib/classes/tpl.inc.php(1366): eval()
mod_fcgid: stderr: #1 /usr/local/ispconfig/interface/lib/classes/tpl.inc.php(769): tpl->_parse()
mod_fcgid: stderr: #2 /usr/local/ispconfig/interface/web/index.php(117): tpl->pparse()
mod_fcgid: stderr: #3 {main}
mod_fcgid: stderr:   thrown in /usr/local/ispconfig/interface/lib/classes/tpl.inc.php(1366) : eval()'d code on line 116

Using debug output, I could narrow it down to either <?php for ($_0=0 ; $_0 < count($this->_arrvars['datalog_changes']); $_0++) {?> or <?php for ($_0=0 ; $_0 < count($this->_arrvars['js_d_includes']); $_0++) {?> not being countable in /usr/local/ispconfig/interface/web/themes/default/templates/main.tpl.htm

Correct behaviour

ISPconfig should load. If I do this before starting the autoinstaller, ISPconfig loads correctly.

sed -i -e '/8.1/s/8\.1/7\.4/g' lib/os/class.ISPConfigUbuntu2204OS.inc.php

Environment

See above.

References

This probably belongs into the php8 branch.

Edited by Jens