diff --git a/lib/mustache/readme_moodle.txt b/lib/mustache/readme_moodle.txt index fc614724699..75b29f4ae75 100644 --- a/lib/mustache/readme_moodle.txt +++ b/lib/mustache/readme_moodle.txt @@ -20,3 +20,6 @@ from the list. If still not available upstream, they will need to be re-applied. - MDL-67114: PHP 7.4 compatibility. Array operations on scalar value. This corresponds to upstream https://github.com/bobthecow/mustache.php/pull/352 +- MDL-73586: PHP 8.0 compatibility. Removed 'mbstring.func_overload' init setting. + This corresponds to upstream commit https://github.com/bobthecow/mustache.php/commit/e7165a33b282ab4d20b3863825caadb46313d62b + that is availbale for the library versions 2.14.1 and up diff --git a/lib/mustache/src/Mustache/Tokenizer.php b/lib/mustache/src/Mustache/Tokenizer.php index 6dbe0cdfa03..71871226a34 100644 --- a/lib/mustache/src/Mustache/Tokenizer.php +++ b/lib/mustache/src/Mustache/Tokenizer.php @@ -97,11 +97,16 @@ class Mustache_Tokenizer // Setting mbstring.func_overload makes things *really* slow. // Let's do everyone a favor and scan this string as ASCII instead. // + // The INI directive was removed in PHP 8.0 so we don't need to check there (and can drop it + // when we remove support for older versions of PHP). + // // @codeCoverageIgnoreStart $encoding = null; - if (function_exists('mb_internal_encoding') && ini_get('mbstring.func_overload') & 2) { - $encoding = mb_internal_encoding(); - mb_internal_encoding('ASCII'); + if (version_compare(PHP_VERSION, '8.0.0', '<')) { + if (function_exists('mb_internal_encoding') && ini_get('mbstring.func_overload') & 2) { + $encoding = mb_internal_encoding(); + mb_internal_encoding('ASCII'); + } } // @codeCoverageIgnoreEnd diff --git a/lib/phpunit/bootstrap.php b/lib/phpunit/bootstrap.php index f3d04406fd9..e8be0752c2d 100644 --- a/lib/phpunit/bootstrap.php +++ b/lib/phpunit/bootstrap.php @@ -39,8 +39,6 @@ ini_set('log_errors', '1'); if (ini_get('opcache.enable') and strtolower(ini_get('opcache.enable')) !== 'off') { if (!ini_get('opcache.save_comments') or strtolower(ini_get('opcache.save_comments')) === 'off') { ini_set('opcache.enable', 0); - } else { - ini_set('opcache.load_comments', 1); } } diff --git a/mod/wiki/classes/external.php b/mod/wiki/classes/external.php index 4a147559517..b51d41bcaf2 100644 --- a/mod/wiki/classes/external.php +++ b/mod/wiki/classes/external.php @@ -512,10 +512,14 @@ class mod_wiki_external extends external_api { $retpage['contentformat'] = $contentformat; } else { // Return the size of the content. - if (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2)) { - $retpage['contentsize'] = mb_strlen($cachedcontent, '8bit'); - } else { - $retpage['contentsize'] = strlen($cachedcontent); + $retpage['contentsize'] = strlen($cachedcontent); + // TODO: Remove this block of code once PHP 8.0 is the min version supported. + // For PHP < 8.0, if strlen() was overloaded, calculate + // the bytes using mb_strlen(..., '8bit'). + if (PHP_VERSION_ID < 80000) { + if (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2)) { + $retpage['contentsize'] = mb_strlen($cachedcontent, '8bit'); + } } } diff --git a/mod/wiki/tests/externallib_test.php b/mod/wiki/tests/externallib_test.php index 324f8d69d79..7e762a3fc0f 100644 --- a/mod/wiki/tests/externallib_test.php +++ b/mod/wiki/tests/externallib_test.php @@ -644,10 +644,14 @@ class externallib_test extends externallib_advanced_testcase { // Check that WS doesn't return page content if includecontent is false, it returns the size instead. foreach ($expectedpages as $i => $expectedpage) { - if (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2)) { - $expectedpages[$i]['contentsize'] = mb_strlen($expectedpages[$i]['cachedcontent'], '8bit'); - } else { - $expectedpages[$i]['contentsize'] = strlen($expectedpages[$i]['cachedcontent']); + $expectedpages[$i]['contentsize'] = strlen($expectedpages[$i]['cachedcontent']); + // TODO: Remove this block of code once PHP 8.0 is the min version supported. + // For PHP < 8.0, if strlen() was overloaded, calculate + // the bytes using mb_strlen(..., '8bit'). + if (PHP_VERSION_ID < 80000) { + if (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2)) { + $expectedpages[$i]['contentsize'] = mb_strlen($expectedpages[$i]['cachedcontent'], '8bit'); + } } unset($expectedpages[$i]['cachedcontent']); unset($expectedpages[$i]['contentformat']);