-
-
Notifications
You must be signed in to change notification settings - Fork 145
Ctype: Give the correct deprecations for PHP 8.1+ #504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
BackEndTea
wants to merge
1
commit into
symfony:1.x
Choose a base branch
from
BackEndTea:chore-correct-deprecation
base: 1.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+34
−17
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,21 @@ 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 | ||
* @param string $function | ||
*/ | ||
public static function checkType($input, $function) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can't we inline this method in convert_int_to_char_for_ctype? |
||
{ | ||
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); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.