Merge branch 'MDL-73586_311' of https://github.com/stronk7/moodle into MOODLE_311_STABLE

This commit is contained in:
Sara Arjona 2022-03-09 16:26:20 +01:00
commit ed07b798e9
5 changed files with 27 additions and 13 deletions

View file

@ -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. - MDL-67114: PHP 7.4 compatibility. Array operations on scalar value.
This corresponds to upstream https://github.com/bobthecow/mustache.php/pull/352 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

View file

@ -97,11 +97,16 @@ class Mustache_Tokenizer
// Setting mbstring.func_overload makes things *really* slow. // Setting mbstring.func_overload makes things *really* slow.
// Let's do everyone a favor and scan this string as ASCII instead. // 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 // @codeCoverageIgnoreStart
$encoding = null; $encoding = null;
if (function_exists('mb_internal_encoding') && ini_get('mbstring.func_overload') & 2) { if (version_compare(PHP_VERSION, '8.0.0', '<')) {
$encoding = mb_internal_encoding(); if (function_exists('mb_internal_encoding') && ini_get('mbstring.func_overload') & 2) {
mb_internal_encoding('ASCII'); $encoding = mb_internal_encoding();
mb_internal_encoding('ASCII');
}
} }
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd

View file

@ -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.enable') and strtolower(ini_get('opcache.enable')) !== 'off') {
if (!ini_get('opcache.save_comments') or strtolower(ini_get('opcache.save_comments')) === 'off') { if (!ini_get('opcache.save_comments') or strtolower(ini_get('opcache.save_comments')) === 'off') {
ini_set('opcache.enable', 0); ini_set('opcache.enable', 0);
} else {
ini_set('opcache.load_comments', 1);
} }
} }

View file

@ -512,10 +512,14 @@ class mod_wiki_external extends external_api {
$retpage['contentformat'] = $contentformat; $retpage['contentformat'] = $contentformat;
} else { } else {
// Return the size of the content. // Return the size of the content.
if (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2)) { $retpage['contentsize'] = strlen($cachedcontent);
$retpage['contentsize'] = mb_strlen($cachedcontent, '8bit'); // TODO: Remove this block of code once PHP 8.0 is the min version supported.
} else { // For PHP < 8.0, if strlen() was overloaded, calculate
$retpage['contentsize'] = strlen($cachedcontent); // 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');
}
} }
} }

View file

@ -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. // Check that WS doesn't return page content if includecontent is false, it returns the size instead.
foreach ($expectedpages as $i => $expectedpage) { foreach ($expectedpages as $i => $expectedpage) {
if (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2)) { $expectedpages[$i]['contentsize'] = strlen($expectedpages[$i]['cachedcontent']);
$expectedpages[$i]['contentsize'] = mb_strlen($expectedpages[$i]['cachedcontent'], '8bit'); // TODO: Remove this block of code once PHP 8.0 is the min version supported.
} else { // For PHP < 8.0, if strlen() was overloaded, calculate
$expectedpages[$i]['contentsize'] = strlen($expectedpages[$i]['cachedcontent']); // 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]['cachedcontent']);
unset($expectedpages[$i]['contentformat']); unset($expectedpages[$i]['contentformat']);