diff options
author | Stefan Giehl <stefan@matomo.org> | 2022-05-17 15:07:09 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-17 15:07:09 +0300 |
commit | 3860159eaa190561896dcade11268193b4b4630b (patch) | |
tree | 22c0e3f4d21a0b79f66aaa0b82b2defa36da0895 /core | |
parent | 0acc68778bcb18931b1f74f3374e85832fe2fee1 (diff) |
Compatibility fixes for PHP 8.1 (#19143)
* Update .travis.yml
* fix php 8.1 deprecation notices
* Revert "run report tests on any PHP version (#18666)"
This reverts commit ec58ab4606cbc6c7f7c3a7aa7f1e9cc5a88e5dfb.
* apply PSR12 code formatting
* fix deprecation notice
* try to fix test
* fix frontcontroller test
* Clearing output buffers with enabled output compression makes problems on some PHP versions
* Set the mysqli error reporting to none, to prevent possible problems on PHP 8.1
Diffstat (limited to 'core')
-rw-r--r-- | core/Db/Adapter/Mysqli.php | 5 | ||||
-rw-r--r-- | core/ProxyHttp.php | 19 | ||||
-rw-r--r-- | core/ReportRenderer/Pdf.php | 2 | ||||
-rw-r--r-- | core/Site.php | 2 | ||||
-rw-r--r-- | core/Tracker/Db/Mysqli.php | 5 |
5 files changed, 29 insertions, 4 deletions
diff --git a/core/Db/Adapter/Mysqli.php b/core/Db/Adapter/Mysqli.php index a46236c570..928e634294 100644 --- a/core/Db/Adapter/Mysqli.php +++ b/core/Db/Adapter/Mysqli.php @@ -82,6 +82,11 @@ class Mysqli extends Zend_Db_Adapter_Mysqli implements AdapterInterface return; } + // The default error reporting of mysqli changed in PHP 8.1. To circumvent problems in our error handling we set + // the erroring reporting to the default that was used prior PHP 8.1 + // See https://php.watch/versions/8.1/mysqli-error-mode for more details + mysqli_report(MYSQLI_REPORT_OFF); + parent::_connect(); $this->_connection->query('SET sql_mode = "' . Db::SQL_MODE . '"'); diff --git a/core/ProxyHttp.php b/core/ProxyHttp.php index f8a99dd34f..3f3eb5fec2 100644 --- a/core/ProxyHttp.php +++ b/core/ProxyHttp.php @@ -125,7 +125,7 @@ class ProxyHttp $phpOutputCompressionEnabled = self::isPhpOutputCompressed(); if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) && !$phpOutputCompressionEnabled) { - list($encoding, $extension) = self::getCompressionEncodingAcceptedByClient(); + [$encoding, $extension] = self::getCompressionEncodingAcceptedByClient(); $filegz = $compressedFileLocation . $extension; if (self::canCompressInPhp()) { @@ -174,10 +174,25 @@ class ProxyHttp // it would break the gzipped response since it would have mixed regular notice/string plus gzipped content // and would not be able to decode the response $levels = ob_get_level(); - for ( $i = 0; $i < $levels; $i++ ) { + for ($i = 0; $i < $levels; $i++) { ob_end_clean(); } + // clearing all output buffers combined with output compressions had bugs on certain PHP versions + // manually removing the Content-Encoding header fixes this + // See https://github.com/php/php-src/issues/8218 + if ( + $phpOutputCompressionEnabled + && ( + version_compare(PHP_VERSION, '8.0.17', '=') + || version_compare(PHP_VERSION, '8.0.18', '=') + || version_compare(PHP_VERSION, '8.1.4', '=') + || version_compare(PHP_VERSION, '8.1.5', '=') + ) + ) { + header_remove("Content-Encoding"); + } + if (!_readfile($file, $byteStart, $byteEnd)) { Common::sendResponseCode(500); } diff --git a/core/ReportRenderer/Pdf.php b/core/ReportRenderer/Pdf.php index 2ec74f4739..84161a2243 100644 --- a/core/ReportRenderer/Pdf.php +++ b/core/ReportRenderer/Pdf.php @@ -169,7 +169,7 @@ class Pdf extends ReportRenderer public function getRenderedReport() { - return $this->TCPDF->Output(null, 'S'); + return $this->TCPDF->Output('', 'S'); } public function renderFrontPage($reportTitle, $prettyDate, $description, $reportMetadata, $segment) diff --git a/core/Site.php b/core/Site.php index 0b47476adb..1efda88bf8 100644 --- a/core/Site.php +++ b/core/Site.php @@ -438,7 +438,7 @@ class Site } $validIds = array(); foreach ($ids as $id) { - $id = trim($id); + $id = is_string($id) ? trim($id) : $id; if (!empty($id) && is_numeric($id) && $id > 0) { $validIds[] = $id; } diff --git a/core/Tracker/Db/Mysqli.php b/core/Tracker/Db/Mysqli.php index 351c1534b8..ceaf12488a 100644 --- a/core/Tracker/Db/Mysqli.php +++ b/core/Tracker/Db/Mysqli.php @@ -105,6 +105,11 @@ class Mysqli extends Db $timer = $this->initProfiler(); } + // The default error reporting of mysqli changed in PHP 8.1. To circumvent problems in our error handling we set + // the erroring reporting to the default that was used prior PHP 8.1 + // See https://php.watch/versions/8.1/mysqli-error-mode for more details + mysqli_report(MYSQLI_REPORT_OFF); + $this->connection = mysqli_init(); |