4 * compatibility functions
6 * This file contains a few functions that might be missing from the PHP build
9 if (!function_exists('ctype_space')) {
11 * Check for whitespace character(s)
17 function ctype_space($text)
19 if (!is_string($text)) return false; #FIXME original treats between -128 and 255 inclusive as ASCII chars
20 if (trim($text) === '') return true;
25 if (!function_exists('ctype_digit')) {
27 * Check for numeric character(s)
33 function ctype_digit($text)
35 if (!is_string($text)) return false; #FIXME original treats between -128 and 255 inclusive as ASCII chars
36 if (preg_match('/^\d+$/', $text)) return true;
41 if (!function_exists('gzopen') && function_exists('gzopen64')) {
43 * work around for PHP compiled against certain zlib versions #865
45 * @link http://stackoverflow.com/questions/23417519/php-zlib-gzopen-not-exists
47 * @param string $filename
49 * @param int $use_include_path
52 function gzopen($filename, $mode, $use_include_path = 0)
54 return gzopen64($filename, $mode, $use_include_path);
58 if (!function_exists('gzseek') && function_exists('gzseek64')) {
60 * work around for PHP compiled against certain zlib versions #865
62 * @link http://stackoverflow.com/questions/23417519/php-zlib-gzopen-not-exists
69 function gzseek($zp, $offset, $whence = SEEK_SET
)
71 return gzseek64($zp, $offset, $whence);
75 if (!function_exists('gztell') && function_exists('gztell64')) {
77 * work around for PHP compiled against certain zlib versions #865
79 * @link http://stackoverflow.com/questions/23417519/php-zlib-gzopen-not-exists
91 * polyfill for PHP < 8
92 * @see https://www.php.net/manual/en/function.str-starts-with
94 if (!function_exists('str_starts_with')) {
95 function str_starts_with(?
string $haystack, ?
string $needle)
97 return 0 === strncmp($haystack, $needle, \
strlen($needle));
102 * polyfill for PHP < 8
103 * @see https://www.php.net/manual/en/function.str-contains
105 if (!function_exists('str_contains')) {
106 function str_contains(?
string $haystack, ?
string $needle)
108 return '' === $needle ||
false !== strpos($haystack, $needle);
113 * polyfill for PHP < 8
114 * @see https://www.php.net/manual/en/function.str-ends-with
116 if (!function_exists('str_ends_with')) {
117 function str_ends_with(?
string $haystack, ?
string $needle)
119 if ('' === $needle ||
$needle === $haystack) {
123 if ('' === $haystack) {
127 $needleLength = \
strlen($needle);
129 return $needleLength <= \
strlen($haystack) && 0 === substr_compare($haystack, $needle, -$needleLength);
134 * polyfill for PHP < 8.1
135 * @see https://www.php.net/manual/en/function.array-is-list
137 if (!function_exists('array_is_list')) {
138 function array_is_list(array $arr)
143 return array_keys($arr) === range(0, count($arr) - 1);