From 052a282ec43a1991c14f46ea0897258106d9d2c8 Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Thu, 24 Oct 2019 18:41:52 +0200 Subject: [PATCH 1/2] MDL-67017 typo3: php74 fixup for typo3 lib 4.7.19 We are using a really outdated Typo3 library (2014) already patched for php73 support. Plus, probably, we'll be soon removing it from core. So we have decided to, instead of upgrade, apply the needed php74 fixes. --- lib/typo3/class.t3lib_cs.php | 66 +++++++++++++++++------------------ lib/typo3/class.t3lib_div.php | 12 +++---- 2 files changed, 39 insertions(+), 39 deletions(-) diff --git a/lib/typo3/class.t3lib_cs.php b/lib/typo3/class.t3lib_cs.php index 00dfc697250..ad1a6409fcd 100644 --- a/lib/typo3/class.t3lib_cs.php +++ b/lib/typo3/class.t3lib_cs.php @@ -679,7 +679,7 @@ class t3lib_cs { $chr = substr($str, $a, 1); $ord = ord($chr); if (isset($this->twoByteSets[$charset])) { // If the charset has two bytes per char - $ord2 = ord($str{$a + 1}); + $ord2 = ord($str[$a + 1]); $ord = $ord << 8 | $ord2; // assume big endian if (isset($this->parsedCharsets[$charset]['local'][$ord])) { // If the local char-number was found in parsed conv. table then we use that, otherwise 127 (no char?) @@ -1164,7 +1164,7 @@ class t3lib_cs { $utf8CaseFolding['toTitle'][$utf8_char] = $this->UnumberToChar(hexdec($title)); } - switch ($cat{0}) { + switch ($cat[0]) { case 'M': // mark (accent, umlaut, ...) $mark["U+$char"] = 1; break; @@ -1224,10 +1224,10 @@ class t3lib_cs { if ($fh) { while (!feof($fh)) { $line = fgets($fh, 4096); - if ($line{0} != '#' && trim($line) != '') { + if ($line[0] != '#' && trim($line) != '') { list($char, $lower, $title, $upper, $cond) = t3lib_div::trimExplode(';', $line); - if ($cond == '' || $cond{0} == '#') { + if ($cond == '' || $cond[0] == '#') { $utf8_char = $this->UnumberToChar(hexdec($char)); if ($char != $lower) { $arr = explode(' ', $lower); @@ -1264,7 +1264,7 @@ class t3lib_cs { if ($fh) { while (!feof($fh)) { $line = fgets($fh, 4096); - if ($line{0} != '#' && trim($line) != '') { + if ($line[0] != '#' && trim($line) != '') { list($char, $translit) = t3lib_div::trimExplode(';', $line); if (!$translit) { $omit["U+$char"] = 1; @@ -1609,12 +1609,12 @@ class t3lib_cs { return $string; } else { if ($len > 0) { - if (strlen($string{$i})) { + if (strlen($string[$i])) { return substr($string, 0, $i) . $crop; } } else { - if (strlen($string{$i - 1})) { + if (strlen($string[$i - 1])) { return $crop . substr($string, $i); } } @@ -1835,8 +1835,8 @@ class t3lib_cs { } $out = ''; - for ($i = 0; strlen($str{$i}); $i++) { - $c = $str{$i}; + for ($i = 0; strlen($str[$i]); $i++) { + $c = $str[$i]; if (isset($map[$c])) { $out .= $map[$c]; } else { @@ -1908,8 +1908,8 @@ class t3lib_cs { */ function utf8_strlen($str) { $n = 0; - for ($i = 0; strlen($str{$i}); $i++) { - $c = ord($str{$i}); + for ($i = 0; strlen($str[$i]); $i++) { + $c = ord($str[$i]); if (!($c & 0x80)) // single-byte (0xxxxxx) { $n++; @@ -1933,15 +1933,15 @@ class t3lib_cs { */ function utf8_strtrunc($str, $len) { $i = $len - 1; - if (ord($str{$i}) & 0x80) { // part of a multibyte sequence - for (; $i > 0 && !(ord($str{$i}) & 0x40); $i--) { + if (ord($str[$i]) & 0x80) { // part of a multibyte sequence + for (; $i > 0 && !(ord($str[$i]) & 0x40); $i--) { // find the first byte ; } if ($i <= 0) { return ''; } // sanity check - for ($bc = 0, $mbs = ord($str{$i}); $mbs & 0x80; $mbs = $mbs << 1) { + for ($bc = 0, $mbs = ord($str[$i]); $mbs & 0x80; $mbs = $mbs << 1) { // calculate number of bytes $bc++; } @@ -2028,8 +2028,8 @@ class t3lib_cs { $d = -1; } - for (; strlen($str{$i}) && $n < $p; $i += $d) { - $c = (int) ord($str{$i}); + for (; strlen($str[$i]) && $n < $p; $i += $d) { + $c = (int) ord($str[$i]); if (!($c & 0x80)) // single-byte (0xxxxxx) { $n++; @@ -2039,13 +2039,13 @@ class t3lib_cs { $n++; } } - if (!strlen($str{$i})) { + if (!strlen($str[$i])) { return FALSE; } // offset beyond string length if ($pos >= 0) { // skip trailing multi-byte data bytes - while ((ord($str{$i}) & 0x80) && !(ord($str{$i}) & 0x40)) { + while ((ord($str[$i]) & 0x80) && !(ord($str[$i]) & 0x40)) { $i++; } } else { @@ -2068,7 +2068,7 @@ class t3lib_cs { function utf8_byte2char_pos($str, $pos) { $n = 0; // number of characters for ($i = $pos; $i > 0; $i--) { - $c = (int) ord($str{$i}); + $c = (int) ord($str[$i]); if (!($c & 0x80)) // single-byte (0xxxxxx) { $n++; @@ -2078,7 +2078,7 @@ class t3lib_cs { $n++; } } - if (!strlen($str{$i})) { + if (!strlen($str[$i])) { return FALSE; } // offset beyond string length @@ -2113,11 +2113,11 @@ class t3lib_cs { return $str; } - for ($i = 0; strlen($str{$i}); $i++) { - $c = ord($str{$i}); + for ($i = 0; strlen($str[$i]); $i++) { + $c = ord($str[$i]); if (!($c & 0x80)) // single-byte (0xxxxxx) { - $mbc = $str{$i}; + $mbc = $str[$i]; } elseif (($c & 0xC0) == 0xC0) { // multi-byte starting byte (11xxxxxx) for ($bc = 0; $c & 0x80; $c = $c << 1) { @@ -2162,8 +2162,8 @@ class t3lib_cs { */ function euc_strtrunc($str, $len, $charset) { $sjis = ($charset == 'shift_jis'); - for ($i = 0; strlen($str{$i}) && $i < $len; $i++) { - $c = ord($str{$i}); + for ($i = 0; strlen($str[$i]) && $i < $len; $i++) { + $c = ord($str[$i]); if ($sjis) { if (($c >= 0x80 && $c < 0xA0) || ($c >= 0xE0)) { $i++; @@ -2175,7 +2175,7 @@ class t3lib_cs { } // advance a double-byte char } } - if (!strlen($str{$i})) { + if (!strlen($str[$i])) { return $str; } // string shorter than supplied length @@ -2232,8 +2232,8 @@ class t3lib_cs { function euc_strlen($str, $charset) { $sjis = ($charset == 'shift_jis'); $n = 0; - for ($i = 0; strlen($str{$i}); $i++) { - $c = ord($str{$i}); + for ($i = 0; strlen($str[$i]); $i++) { + $c = ord($str[$i]); if ($sjis) { if (($c >= 0x80 && $c < 0xA0) || ($c >= 0xE0)) { $i++; @@ -2273,8 +2273,8 @@ class t3lib_cs { $d = -1; } - for (; strlen($str{$i}) && $n < $p; $i += $d) { - $c = ord($str{$i}); + for (; strlen($str[$i]) && $n < $p; $i += $d) { + $c = ord($str[$i]); if ($sjis) { if (($c >= 0x80 && $c < 0xA0) || ($c >= 0xE0)) { $i += $d; @@ -2288,7 +2288,7 @@ class t3lib_cs { $n++; } - if (!strlen($str{$i})) { + if (!strlen($str[$i])) { return FALSE; } // offset beyond string length @@ -2331,8 +2331,8 @@ class t3lib_cs { $sjis = ($charset == 'shift_jis'); $out = ''; - for ($i = 0; strlen($str{$i}); $i++) { - $mbc = $str{$i}; + for ($i = 0; strlen($str[$i]); $i++) { + $mbc = $str[$i]; $c = ord($mbc); if ($sjis) { diff --git a/lib/typo3/class.t3lib_div.php b/lib/typo3/class.t3lib_div.php index 243db4d9e87..ad761763f0d 100644 --- a/lib/typo3/class.t3lib_div.php +++ b/lib/typo3/class.t3lib_div.php @@ -1363,7 +1363,7 @@ final class t3lib_div { $bytesToGenerate = max(4096, $bytesToReturn); // if we have not enough random bytes cached, we generate new ones - if (!isset($bytes{$bytesToReturn - 1})) { + if (!isset($bytes[$bytesToReturn - 1])) { if (TYPO3_OS === 'WIN') { // Openssl seems to be deadly slow on Windows, so try to use mcrypt // Windows PHP versions have a bug when using urandom source (see #24410) @@ -1372,18 +1372,18 @@ final class t3lib_div { // Try to use native PHP functions first, precedence has openssl $bytes .= self::generateRandomBytesOpenSsl($bytesToGenerate); - if (!isset($bytes{$bytesToReturn - 1})) { + if (!isset($bytes[$bytesToReturn - 1])) { $bytes .= self::generateRandomBytesMcrypt($bytesToGenerate, MCRYPT_DEV_URANDOM); } // If openssl and mcrypt failed, try /dev/urandom - if (!isset($bytes{$bytesToReturn - 1})) { + if (!isset($bytes[$bytesToReturn - 1])) { $bytes .= self::generateRandomBytesUrandom($bytesToGenerate); } } // Fall back if other random byte generation failed until now - if (!isset($bytes{$bytesToReturn - 1})) { + if (!isset($bytes[$bytesToReturn - 1])) { $bytes .= self::generateRandomBytesFallback($bytesToReturn); } } @@ -1453,7 +1453,7 @@ final class t3lib_div { $bytes = ''; // We initialize with somewhat random. $randomState = $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] . base_convert(memory_get_usage() % pow(10, 6), 10, 2) . microtime() . uniqid('') . getmypid(); - while (!isset($bytes{$bytesToReturn - 1})) { + while (!isset($bytes[$bytesToReturn - 1])) { $randomState = sha1(microtime() . mt_rand() . $randomState); $bytes .= sha1(mt_rand() . $randomState, TRUE); } @@ -5318,7 +5318,7 @@ final class t3lib_div { $matches = preg_split('/(.?###.+###.?|\(|\))/', $line, -1, PREG_SPLIT_NO_EMPTY); foreach ($matches as $part) { $oldPart = $part; - $partWasQuoted = ($part{0} == '"'); + $partWasQuoted = ($part[0] == '"'); $part = trim($part, '"'); switch ((string) $enc) { case 'base64': From ba5aa5fe194b58d9c89920f61b9d86090ac0a708 Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Thu, 24 Oct 2019 18:48:30 +0200 Subject: [PATCH 2/2] MDL-67017 typo3: add details to readme --- lib/typo3/readme_moodle.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/typo3/readme_moodle.txt b/lib/typo3/readme_moodle.txt index cb1e332561b..ad6bf1c38c8 100644 --- a/lib/typo3/readme_moodle.txt +++ b/lib/typo3/readme_moodle.txt @@ -10,6 +10,11 @@ Procedure: Local changes (to verify/apply with new imports): +- MDL-67017: PHP 7.4 compatibility. Curly brackets. + Remove all the deprecated curly bracket uses {} to access to strings/arrays + by key. We haven't looked how this is fixed upstream because plans include + to remove this library from core (see MDL-65809) + - MDL-63967: PHP 7.3 compatibility. lib/typo3/class.t3lib_div.php: FILTER_FLAG_SCHEME_REQUIRED is deprecated and implied with FILTER_VALIDATE_URL. This is fixed upstream since Typo 6, with