summaryrefslogtreecommitdiff
path: root/ext/intl
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2020-11-30 16:45:48 +0100
committerNikita Popov <nikita.ppv@gmail.com>2021-02-11 21:46:13 +0100
commitb10416a652d26577a22fe0b183b2258b20c8bb86 (patch)
tree3b79102286b2307575f487bf97d572ffc292631d /ext/intl
parentf06895488a5fabd27ac4c2e66a9d311f14d8594e (diff)
downloadphp-git-b10416a652d26577a22fe0b183b2258b20c8bb86.tar.gz
Deprecate passing null to non-nullable arg of internal function
This deprecates passing null to non-nullable scale arguments of internal functions, with the eventual goal of making the behavior consistent with userland functions, where null is never accepted for non-nullable arguments. This change is expected to cause quite a lot of fallout. In most cases, calling code should be adjusted to avoid passing null. In some cases, PHP should be adjusted to make some function arguments nullable. I have already fixed a number of functions before landing this, but feel free to file a bug if you encounter a function that doesn't accept null, but probably should. (The rule of thumb for this to be applicable is that the function must have special behavior for 0 or "", which is distinct from the natural behavior of the parameter.) RFC: https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg Closes GH-6475.
Diffstat (limited to 'ext/intl')
-rw-r--r--ext/intl/tests/bug48227.phpt4
-rw-r--r--ext/intl/tests/bug72241.phpt5
-rw-r--r--ext/intl/tests/collator_compare_variant2.phpt10
-rw-r--r--ext/intl/tests/collator_get_sort_key_variant7.phpt4
-rw-r--r--ext/intl/tests/formatter_fail.phpt12
-rw-r--r--ext/intl/tests/gregoriancalendar___construct_error.phpt2
-rw-r--r--ext/intl/tests/gregoriancalendar___construct_variant1.phpt2
-rw-r--r--ext/intl/tests/msgfmt_fail2.phpt12
-rw-r--r--ext/intl/tests/ut_common.inc2
9 files changed, 37 insertions, 16 deletions
diff --git a/ext/intl/tests/bug48227.phpt b/ext/intl/tests/bug48227.phpt
index 11f89df535..b143a7eda2 100644
--- a/ext/intl/tests/bug48227.phpt
+++ b/ext/intl/tests/bug48227.phpt
@@ -15,8 +15,10 @@ foreach (['', 1, NULL, $x] as $value) {
}
?>
---EXPECT--
+--EXPECTF--
NumberFormatter::format(): Argument #1 ($num) must be of type int|float, string given
string(1) "1"
+
+Deprecated: NumberFormatter::format(): Passing null to parameter #1 ($num) of type int|float is deprecated in %s on line %d
string(1) "0"
NumberFormatter::format(): Argument #1 ($num) must be of type int|float, NumberFormatter given
diff --git a/ext/intl/tests/bug72241.phpt b/ext/intl/tests/bug72241.phpt
index 05336969e2..c2017d7470 100644
--- a/ext/intl/tests/bug72241.phpt
+++ b/ext/intl/tests/bug72241.phpt
@@ -6,8 +6,7 @@ Bug #72241: get_icu_value_internal out-of-bounds read
<?php
$var1=str_repeat("A", 1000);
$out = locale_get_primary_language($var1);
-echo strlen($out) . PHP_EOL;
-echo unpack('H*', $out)[1] . PHP_EOL;
+var_dump($out);
?>
--EXPECT--
-0
+NULL
diff --git a/ext/intl/tests/collator_compare_variant2.phpt b/ext/intl/tests/collator_compare_variant2.phpt
index 15c725bc4f..9be10e2935 100644
--- a/ext/intl/tests/collator_compare_variant2.phpt
+++ b/ext/intl/tests/collator_compare_variant2.phpt
@@ -71,12 +71,11 @@ function ut_main()
array( 'ab' , 'b' ),
array( 'ab' , 'a' ),
array( 123 , 'abc' ),
- array( 'ac' , null ),
+ array( 'ac' , '' ),
array( '.' , '.' ),
// Try to compare long strings.
array( 'abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcde',
'abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdea'),
- array( null , null )
);
$res_str .= compare_pairs( 'en_US', $test_params );
@@ -91,7 +90,7 @@ function ut_main()
array( 'а', 'b' ),
array( 'а', 'bb' ),
array( 'а', 'ab' ),
- array( 'а', null )
+ array( 'а', '' )
);
$res_str .= compare_pairs( 'ru_RU', $test_params );
@@ -120,10 +119,9 @@ ut_run();
'ab' < 'b'
'ab' > 'a'
123 < 'abc'
-'ac' > NULL
+'ac' > ''
'.' = '.'
'abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcde' < 'abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdea'
-NULL = NULL
'а' < 'б'
'а' < 'аа'
'аб' < 'ба'
@@ -131,5 +129,5 @@ NULL = NULL
'а' < 'b'
'а' < 'bb'
'а' < 'ab'
-'а' > NULL
+'а' > ''
'y' < 'k'
diff --git a/ext/intl/tests/collator_get_sort_key_variant7.phpt b/ext/intl/tests/collator_get_sort_key_variant7.phpt
index 8ac0154d4f..12dd66aece 100644
--- a/ext/intl/tests/collator_get_sort_key_variant7.phpt
+++ b/ext/intl/tests/collator_get_sort_key_variant7.phpt
@@ -33,7 +33,7 @@ function ut_main()
$test_params = array(
'abc', 'abd', 'aaa',
'аа', 'а', 'z',
- '', null , '3',
+ '', '3',
'y' , 'i' , 'k'
);
@@ -70,8 +70,6 @@ source: z
key: 5c01050105
source:
key: 0101
-source:
-key: 0101
source: 3
key: 1901050105
source: y
diff --git a/ext/intl/tests/formatter_fail.phpt b/ext/intl/tests/formatter_fail.phpt
index 937a52f098..1d9ca34128 100644
--- a/ext/intl/tests/formatter_fail.phpt
+++ b/ext/intl/tests/formatter_fail.phpt
@@ -107,6 +107,18 @@ ArgumentCountError: NumberFormatter::create() expects at least 2 arguments, 0 gi
Error: NumberFormatter object is already constructed in %s on line %d
'U_ZERO_ERROR'
+Deprecated: NumberFormatter::__construct(): Passing null to parameter #1 ($locale) of type string is deprecated in %s on line %d
+
+Deprecated: NumberFormatter::__construct(): Passing null to parameter #2 ($style) of type int is deprecated in %s on line %d
+
+Deprecated: NumberFormatter::create(): Passing null to parameter #1 ($locale) of type string is deprecated in %s on line %d
+
+Deprecated: NumberFormatter::create(): Passing null to parameter #2 ($style) of type int is deprecated in %s on line %d
+
+Deprecated: numfmt_create(): Passing null to parameter #1 ($locale) of type string is deprecated in %s on line %d
+
+Deprecated: numfmt_create(): Passing null to parameter #2 ($style) of type int is deprecated in %s on line %d
+
IntlException: Constructor failed in %s on line %d
'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR'
'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR'
diff --git a/ext/intl/tests/gregoriancalendar___construct_error.phpt b/ext/intl/tests/gregoriancalendar___construct_error.phpt
index 2bc87c723d..4ddcca3228 100644
--- a/ext/intl/tests/gregoriancalendar___construct_error.phpt
+++ b/ext/intl/tests/gregoriancalendar___construct_error.phpt
@@ -29,7 +29,7 @@ try {
echo $e->getMessage(), "\n";
}
try {
- var_dump(new IntlGregorianCalendar(1,2,3,4,NULL,array()));
+ var_dump(new IntlGregorianCalendar(1,2,3,4,5,array()));
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}
diff --git a/ext/intl/tests/gregoriancalendar___construct_variant1.phpt b/ext/intl/tests/gregoriancalendar___construct_variant1.phpt
index 22dae52d77..1a225fe620 100644
--- a/ext/intl/tests/gregoriancalendar___construct_variant1.phpt
+++ b/ext/intl/tests/gregoriancalendar___construct_variant1.phpt
@@ -10,7 +10,7 @@ ini_set("intl.error_level", E_WARNING);
date_default_timezone_set('Europe/Amsterdam');
-$intlcal = intlgregcal_create_instance(2012, 1, 29, 16, 0, NULL);
+$intlcal = intlgregcal_create_instance(2012, 1, 29, 16, 0, 0);
var_dump($intlcal->getTimeZone()->getId());
var_dump($intlcal->getTime(), (float)strtotime('2012-02-29 16:00:00') * 1000);
diff --git a/ext/intl/tests/msgfmt_fail2.phpt b/ext/intl/tests/msgfmt_fail2.phpt
index f604de0727..8823e36a6f 100644
--- a/ext/intl/tests/msgfmt_fail2.phpt
+++ b/ext/intl/tests/msgfmt_fail2.phpt
@@ -126,9 +126,21 @@ ArgumentCountError: msgfmt_create() expects exactly 2 arguments, 1 given in %s o
ArgumentCountError: MessageFormatter::create() expects exactly 2 arguments, 1 given in %s on line %d
'U_ZERO_ERROR'
+Deprecated: MessageFormatter::__construct(): Passing null to parameter #1 ($locale) of type string is deprecated in %s on line %d
+
+Deprecated: MessageFormatter::__construct(): Passing null to parameter #2 ($pattern) of type string is deprecated in %s on line %d
+
IntlException: msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR in %s on line %d
'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
+
+Deprecated: MessageFormatter::create(): Passing null to parameter #1 ($locale) of type string is deprecated in %s on line %d
+
+Deprecated: MessageFormatter::create(): Passing null to parameter #2 ($pattern) of type string is deprecated in %s on line %d
'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
+
+Deprecated: msgfmt_create(): Passing null to parameter #1 ($locale) of type string is deprecated in %s on line %d
+
+Deprecated: msgfmt_create(): Passing null to parameter #2 ($pattern) of type string is deprecated in %s on line %d
'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR'
IntlException: msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR in %s on line %d
diff --git a/ext/intl/tests/ut_common.inc b/ext/intl/tests/ut_common.inc
index 4a2675b01f..fdc013dea4 100644
--- a/ext/intl/tests/ut_common.inc
+++ b/ext/intl/tests/ut_common.inc
@@ -142,7 +142,7 @@ function ut_nfmt_create( $locale, $style, $pattern = null )
return numfmt_create( $locale, $style, $pattern );
}
}
-function ut_nfmt_format( $fmt, $number, $type = null )
+function ut_nfmt_format( $fmt, $number, $type = NumberFormatter::TYPE_DEFAULT )
{
return $GLOBALS['oo-mode'] ? $fmt->format( $number, $type ) : numfmt_format( $fmt, $number, $type );
}