diff --git a/src/Ctype/Ctype.php b/src/Ctype/Ctype.php index ba75a2c95..b19c2f151 100644 --- a/src/Ctype/Ctype.php +++ b/src/Ctype/Ctype.php @@ -31,7 +31,8 @@ final class Ctype */ public static function ctype_alnum($text) { - $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); + self::checkType($text, __FUNCTION__); + $text = self::convert_int_to_char_for_ctype($text); return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z0-9]/', $text); } @@ -47,7 +48,8 @@ public static function ctype_alnum($text) */ public static function ctype_alpha($text) { - $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); + self::checkType($text, __FUNCTION__); + $text = self::convert_int_to_char_for_ctype($text); return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z]/', $text); } @@ -63,7 +65,8 @@ public static function ctype_alpha($text) */ public static function ctype_cntrl($text) { - $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); + self::checkType($text, __FUNCTION__); + $text = self::convert_int_to_char_for_ctype($text); return \is_string($text) && '' !== $text && !preg_match('/[^\x00-\x1f\x7f]/', $text); } @@ -79,7 +82,8 @@ public static function ctype_cntrl($text) */ public static function ctype_digit($text) { - $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); + self::checkType($text, __FUNCTION__); + $text = self::convert_int_to_char_for_ctype($text); return \is_string($text) && '' !== $text && !preg_match('/[^0-9]/', $text); } @@ -95,7 +99,8 @@ public static function ctype_digit($text) */ public static function ctype_graph($text) { - $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); + self::checkType($text, __FUNCTION__); + $text = self::convert_int_to_char_for_ctype($text); return \is_string($text) && '' !== $text && !preg_match('/[^!-~]/', $text); } @@ -111,7 +116,8 @@ public static function ctype_graph($text) */ public static function ctype_lower($text) { - $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); + self::checkType($text, __FUNCTION__); + $text = self::convert_int_to_char_for_ctype($text); return \is_string($text) && '' !== $text && !preg_match('/[^a-z]/', $text); } @@ -127,7 +133,8 @@ public static function ctype_lower($text) */ public static function ctype_print($text) { - $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); + self::checkType($text, __FUNCTION__); + $text = self::convert_int_to_char_for_ctype($text); return \is_string($text) && '' !== $text && !preg_match('/[^ -~]/', $text); } @@ -143,7 +150,8 @@ public static function ctype_print($text) */ public static function ctype_punct($text) { - $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); + self::checkType($text, __FUNCTION__); + $text = self::convert_int_to_char_for_ctype($text); return \is_string($text) && '' !== $text && !preg_match('/[^!-\/\:-@\[-`\{-~]/', $text); } @@ -159,7 +167,8 @@ public static function ctype_punct($text) */ public static function ctype_space($text) { - $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); + self::checkType($text, __FUNCTION__); + $text = self::convert_int_to_char_for_ctype($text); return \is_string($text) && '' !== $text && !preg_match('/[^\s]/', $text); } @@ -175,7 +184,8 @@ public static function ctype_space($text) */ public static function ctype_upper($text) { - $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); + self::checkType($text, __FUNCTION__); + $text = self::convert_int_to_char_for_ctype($text); return \is_string($text) && '' !== $text && !preg_match('/[^A-Z]/', $text); } @@ -191,7 +201,8 @@ public static function ctype_upper($text) */ public static function ctype_xdigit($text) { - $text = self::convert_int_to_char_for_ctype($text, __FUNCTION__); + self::checkType($text, __FUNCTION__); + $text = self::convert_int_to_char_for_ctype($text); return \is_string($text) && '' !== $text && !preg_match('/[^A-Fa-f0-9]/', $text); } @@ -205,11 +216,10 @@ public static function ctype_xdigit($text) * Any other integer is interpreted as a string containing the decimal digits of the integer. * * @param mixed $int - * @param string $function * * @return mixed */ - private static function convert_int_to_char_for_ctype($int, $function) + private static function convert_int_to_char_for_ctype($int) { if (!\is_int($int)) { return $int; @@ -219,14 +229,20 @@ private static function convert_int_to_char_for_ctype($int, $function) return (string) $int; } - if (\PHP_VERSION_ID >= 80100) { - @trigger_error($function.'(): Argument of type int will be interpreted as string in the future', \E_USER_DEPRECATED); - } - if ($int < 0) { $int += 256; } return \chr($int); } + + /** + * @param mixed $input + */ + private static function checkType($input, string $function): void + { + if (\PHP_VERSION_ID >= 80100 && !\is_string($input)) { + @trigger_error($function.'(): Argument of type '.get_debug_type($input).' will be interpreted as string in the future', \E_USER_DEPRECATED); + } + } } diff --git a/src/Ctype/composer.json b/src/Ctype/composer.json index 131ca7adb..99d74b24e 100644 --- a/src/Ctype/composer.json +++ b/src/Ctype/composer.json @@ -16,7 +16,8 @@ } ], "require": { - "php": ">=7.2" + "php": ">=7.2", + "symfony/polyfill-php80": "^1.31" }, "provide": { "ext-ctype": "*"