@@ -834,19 +834,32 @@ public static function mb_ord($s, $encoding = null)
834
834
return $ code ;
835
835
}
836
836
837
- public static function mb_str_pad (string $ string , int $ length , string $ pad_string = ' ' , int $ pad_type = \STR_PAD_RIGHT , ?string $ encoding = null ): string
837
+ /** @return string|false */
838
+ public static function mb_str_pad (string $ string , int $ length , string $ pad_string = ' ' , int $ pad_type = \STR_PAD_RIGHT , ?string $ encoding = null )
838
839
{
839
840
if (!\in_array ($ pad_type , [\STR_PAD_RIGHT , \STR_PAD_LEFT , \STR_PAD_BOTH ], true )) {
841
+ if (\PHP_VERSION_ID < 80000 ) {
842
+ trigger_error ('mb_str_pad(): Argument #4 ($pad_type) must be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH ' , \E_USER_WARNING );
843
+
844
+ return false ;
845
+ }
846
+
840
847
throw new \ValueError ('mb_str_pad(): Argument #4 ($pad_type) must be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH ' );
841
848
}
842
849
843
850
if (null === $ encoding ) {
844
851
$ encoding = self ::mb_internal_encoding ();
845
- } else {
846
- self :: assertEncoding ( $ encoding , ' mb_str_pad(): Argument #5 ($encoding) must be a valid encoding, "%s" given ' ) ;
852
+ } elseif (! self :: assertEncoding ( $ encoding , ' mb_str_pad(): Argument #5 ($encoding) must be a valid encoding, "%s" given ' )) {
853
+ return false ;
847
854
}
848
855
849
856
if (self ::mb_strlen ($ pad_string , $ encoding ) <= 0 ) {
857
+ if (\PHP_VERSION_ID < 80000 ) {
858
+ trigger_error ('mb_str_pad(): Argument #3 ($pad_string) must be a non-empty string ' , \E_USER_WARNING );
859
+
860
+ return false ;
861
+ }
862
+
850
863
throw new \ValueError ('mb_str_pad(): Argument #3 ($pad_string) must be a non-empty string ' );
851
864
}
852
865
@@ -869,12 +882,13 @@ public static function mb_str_pad(string $string, int $length, string $pad_strin
869
882
}
870
883
}
871
884
872
- public static function mb_ucfirst (string $ string , ?string $ encoding = null ): string
885
+ /** @return string|false */
886
+ public static function mb_ucfirst (string $ string , ?string $ encoding = null )
873
887
{
874
888
if (null === $ encoding ) {
875
889
$ encoding = self ::mb_internal_encoding ();
876
- } else {
877
- self :: assertEncoding ( $ encoding , ' mb_ucfirst(): Argument #2 ($encoding) must be a valid encoding, "%s" given ' ) ;
890
+ } elseif (! self :: assertEncoding ( $ encoding , ' mb_ucfirst(): Argument #2 ($encoding) must be a valid encoding, "%s" given ' )) {
891
+ return false ;
878
892
}
879
893
880
894
$ firstChar = mb_substr ($ string , 0 , 1 , $ encoding );
@@ -883,12 +897,13 @@ public static function mb_ucfirst(string $string, ?string $encoding = null): str
883
897
return $ firstChar .mb_substr ($ string , 1 , null , $ encoding );
884
898
}
885
899
886
- public static function mb_lcfirst (string $ string , ?string $ encoding = null ): string
900
+ /** @return string|false */
901
+ public static function mb_lcfirst (string $ string , ?string $ encoding = null )
887
902
{
888
903
if (null === $ encoding ) {
889
904
$ encoding = self ::mb_internal_encoding ();
890
- } else {
891
- self :: assertEncoding ( $ encoding , ' mb_lcfirst(): Argument #2 ($encoding) must be a valid encoding, "%s" given ' ) ;
905
+ } elseif (! self :: assertEncoding ( $ encoding , ' mb_lcfirst(): Argument #2 ($encoding) must be a valid encoding, "%s" given ' )) {
906
+ return false ;
892
907
}
893
908
894
909
$ firstChar = mb_substr ($ string , 0 , 1 , $ encoding );
@@ -971,27 +986,31 @@ private static function getEncoding($encoding)
971
986
return $ encoding ;
972
987
}
973
988
974
- public static function mb_trim (string $ string , ?string $ characters = null , ?string $ encoding = null ): string
989
+ /** @return string|false */
990
+ public static function mb_trim (string $ string , ?string $ characters = null , ?string $ encoding = null )
975
991
{
976
992
return self ::mb_internal_trim ('{^[%s]+|[%1$s]+$}Du ' , $ string , $ characters , $ encoding , __FUNCTION__ );
977
993
}
978
994
979
- public static function mb_ltrim (string $ string , ?string $ characters = null , ?string $ encoding = null ): string
995
+ /** @return string|false */
996
+ public static function mb_ltrim (string $ string , ?string $ characters = null , ?string $ encoding = null )
980
997
{
981
998
return self ::mb_internal_trim ('{^[%s]+}Du ' , $ string , $ characters , $ encoding , __FUNCTION__ );
982
999
}
983
1000
984
- public static function mb_rtrim (string $ string , ?string $ characters = null , ?string $ encoding = null ): string
1001
+ /** @return string|false */
1002
+ public static function mb_rtrim (string $ string , ?string $ characters = null , ?string $ encoding = null )
985
1003
{
986
1004
return self ::mb_internal_trim ('{[%s]+$}D ' , $ string , $ characters , $ encoding , __FUNCTION__ );
987
1005
}
988
1006
989
- private static function mb_internal_trim (string $ regex , string $ string , ?string $ characters , ?string $ encoding , string $ function ): string
1007
+ /** @return string|false */
1008
+ private static function mb_internal_trim (string $ regex , string $ string , ?string $ characters , ?string $ encoding , string $ function )
990
1009
{
991
1010
if (null === $ encoding ) {
992
1011
$ encoding = self ::mb_internal_encoding ();
993
- } else {
994
- self :: assertEncoding ( $ encoding , $ function . ' (): Argument #3 ($encoding) must be a valid encoding, "%s" given ' ) ;
1012
+ } elseif (! self :: assertEncoding ( $ encoding , $ function . ' (): Argument #3 ($encoding) must be a valid encoding, "%s" given ' )) {
1013
+ return false ;
995
1014
}
996
1015
997
1016
if ('' === $ characters ) {
@@ -1029,17 +1048,22 @@ private static function mb_internal_trim(string $regex, string $string, ?string
1029
1048
return iconv ('UTF-8 ' , $ encoding .'//IGNORE ' , $ string );
1030
1049
}
1031
1050
1032
- private static function assertEncoding (string $ encoding , string $ errorFormat ): void
1051
+ private static function assertEncoding (string $ encoding , string $ errorFormat ): bool
1033
1052
{
1034
1053
try {
1035
1054
$ validEncoding = @self ::mb_check_encoding ('' , $ encoding );
1036
1055
} catch (\ValueError $ e ) {
1037
1056
throw new \ValueError (sprintf ($ errorFormat , $ encoding ));
1038
1057
}
1039
1058
1040
- // BC for PHP 7.3 and lower
1041
1059
if (!$ validEncoding ) {
1042
- throw new \ValueError (sprintf ($ errorFormat , $ encoding ));
1060
+ if (\PHP_VERSION_ID >= 80000 ) {
1061
+ throw new \ValueError (sprintf ($ errorFormat , $ encoding ));
1062
+ }
1063
+
1064
+ trigger_error (sprintf ($ errorFormat , $ encoding ), E_USER_WARNING );
1043
1065
}
1066
+
1067
+ return $ validEncoding ;
1044
1068
}
1045
1069
}
0 commit comments