diff options
| author | 2024-09-06 09:06:46 +0200 | |
|---|---|---|
| committer | 2024-09-06 09:06:46 +0200 | |
| commit | a81656c3ed5b8fe0f31794a4fbe0d1a907fca8e8 (patch) | |
| tree | 8bf49bd876aaebc985a9fb1214863190a799cbee /lib/lib_rss.php | |
| parent | 8f7c3473a76809efc88814253722c76f0cc8eb04 (diff) | |
Upgrade to PHP 8.1 (#6711)
* Upgrade to PHP 8.1
As discussed in https://github.com/FreshRSS/FreshRSS/discussions/5474
https://www.php.net/releases/8.0/en.php
https://www.php.net/releases/8.1/en.php
Upgrade to available native type declarations
https://php.net/language.types.declarations
Upgrade to https://phpunit.de/announcements/phpunit-10.html which requires PHP 8.1+ (good timing, as version 9 was not maintained anymore)
Upgrade `:oldest` Docker dev image to oldest Alpine version supporting PHP 8.1: Alpine 3.16, which includes PHP 8.1.22.
* Include 6736
https://github.com/FreshRSS/FreshRSS/pull/6736
Diffstat (limited to 'lib/lib_rss.php')
| -rw-r--r-- | lib/lib_rss.php | 43 |
1 files changed, 4 insertions, 39 deletions
diff --git a/lib/lib_rss.php b/lib/lib_rss.php index d066bd254..61055153c 100644 --- a/lib/lib_rss.php +++ b/lib/lib_rss.php @@ -5,37 +5,12 @@ if (version_compare(PHP_VERSION, FRESHRSS_MIN_PHP_VERSION, '<')) { die(sprintf('FreshRSS error: FreshRSS requires PHP %s+!', FRESHRSS_MIN_PHP_VERSION)); } -if (!function_exists('array_is_list')) { - /** - * Polyfill for PHP <8.1 - * https://php.net/array-is-list#127044 - * @param array<mixed> $array - */ - function array_is_list(array $array): bool { - $i = -1; - foreach ($array as $k => $v) { - ++$i; - if ($k !== $i) { - return false; - } - } - return true; - } -} - if (!function_exists('mb_strcut')) { function mb_strcut(string $str, int $start, ?int $length = null, string $encoding = 'UTF-8'): string { return substr($str, $start, $length) ?: ''; } } -if (!function_exists('str_starts_with')) { - /** Polyfill for PHP <8.0 */ - function str_starts_with(string $haystack, string $needle): bool { - return strncmp($haystack, $needle, strlen($needle)) === 0; - } -} - if (!function_exists('syslog')) { if (COPY_SYSLOG_TO_STDERR && !defined('STDERR')) { define('STDERR', fopen('php://stderr', 'w')); @@ -149,14 +124,7 @@ function idn_to_puny(string $url): string { if (function_exists('idn_to_ascii')) { $idn = parse_url($url, PHP_URL_HOST); if (is_string($idn) && $idn != '') { - // https://wiki.php.net/rfc/deprecate-and-remove-intl_idna_variant_2003 - if (defined('INTL_IDNA_VARIANT_UTS46')) { - $puny = idn_to_ascii($idn, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46); - } elseif (defined('INTL_IDNA_VARIANT_2003')) { - $puny = idn_to_ascii($idn, IDNA_DEFAULT, INTL_IDNA_VARIANT_2003); - } else { - $puny = idn_to_ascii($idn); - } + $puny = idn_to_ascii($idn); $pos = strpos($url, $idn); if ($puny != false && $pos !== false) { $url = substr_replace($url, $puny, $pos, strlen($idn)); @@ -166,10 +134,7 @@ function idn_to_puny(string $url): string { return $url; } -/** - * @return string|false - */ -function checkUrl(string $url, bool $fixScheme = true) { +function checkUrl(string $url, bool $fixScheme = true): string|false { $url = trim($url); if ($url == '') { return ''; @@ -178,7 +143,7 @@ function checkUrl(string $url, bool $fixScheme = true) { $url = 'https://' . ltrim($url, '/'); } - $url = idn_to_puny($url); //PHP bug #53474 IDN + $url = idn_to_puny($url); // https://bugs.php.net/bug.php?id=53474 $urlRelaxed = str_replace('_', 'z', $url); //PHP discussion #64948 Underscore if (is_string(filter_var($urlRelaxed, FILTER_VALIDATE_URL))) { @@ -279,7 +244,7 @@ function html_only_entity_decode(?string $text): string { * @param array<string,mixed>|string $log * @return array<string,mixed>|string */ -function sensitive_log($log) { +function sensitive_log($log): array|string { if (is_array($log)) { foreach ($log as $k => $v) { if (in_array($k, ['api_key', 'Passwd', 'T'], true)) { |
