From 5d2fba084ec40e7c25889207f773a48266959291 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Sat, 4 Jan 2020 11:01:59 +0100 Subject: [PATCH] Throw exception for unconstructed intl objects --- ext/intl/breakiterator/breakiterator_class.h | 4 ++-- ext/intl/calendar/calendar_class.h | 4 ++-- ext/intl/common/common_enum.h | 4 ++-- ext/intl/dateformat/dateformat_class.h | 4 ++-- ext/intl/formatter/formatter_class.h | 5 ++--- ext/intl/msgformat/msgformat_class.h | 5 ++--- ext/intl/resourcebundle/resourcebundle.stub.php | 4 ++-- ext/intl/resourcebundle/resourcebundle_arginfo.h | 6 ++---- ext/intl/resourcebundle/resourcebundle_class.h | 8 +++----- ext/intl/spoofchecker/spoofchecker.stub.php | 6 +++--- ext/intl/spoofchecker/spoofchecker_class.h | 5 ++--- ext/intl/tests/symfony_format_type_double_intl1.phpt | 12 ++++++------ ext/intl/tests/symfony_format_type_double_intl2.phpt | 12 ++++++------ ext/intl/tests/symfony_format_type_double_intl3.phpt | 12 ++++++------ ext/intl/tests/symfony_format_type_double_intl4.phpt | 11 ++++++----- ext/intl/tests/symfony_format_type_int32_intl1.phpt | 12 ++++++------ ext/intl/tests/symfony_format_type_int32_intl2.phpt | 12 ++++++------ ext/intl/tests/symfony_format_type_int32_intl3.phpt | 12 ++++++------ ext/intl/tests/symfony_format_type_int32_intl4.phpt | 12 ++++++------ ext/intl/tests/symfony_format_type_int32_intl5.phpt | 12 ++++++------ ext/intl/tests/symfony_format_type_int32_intl6.phpt | 12 ++++++------ ext/intl/tests/symfony_format_type_int32_intl7.phpt | 12 ++++++------ ext/intl/tests/symfony_format_type_int64_intl2.phpt | 12 ++++++------ ext/intl/tests/symfony_format_type_int64_intl3.phpt | 12 ++++++------ ext/intl/tests/symfony_format_type_int64_intl4.phpt | 12 ++++++------ ext/intl/tests/symfony_format_type_int64_intl5.phpt | 12 ++++++------ ext/intl/tests/symfony_format_type_int64_intl6.phpt | 12 ++++++------ ext/intl/tests/symfony_format_type_int64_intl7.phpt | 12 ++++++------ ext/intl/tests/symfony_format_type_int64_intl8.phpt | 12 ++++++------ ext/intl/timezone/timezone.stub.php | 8 ++++---- ext/intl/timezone/timezone_arginfo.h | 6 ++++-- ext/intl/timezone/timezone_class.h | 4 ++-- ext/intl/transliterator/transliterator_class.h | 4 ++-- 33 files changed, 144 insertions(+), 148 deletions(-) diff --git a/ext/intl/breakiterator/breakiterator_class.h b/ext/intl/breakiterator/breakiterator_class.h index ce95c65984a0f..ae5eeab82100c 100644 --- a/ext/intl/breakiterator/breakiterator_class.h +++ b/ext/intl/breakiterator/breakiterator_class.h @@ -58,8 +58,8 @@ static inline BreakIterator_object *php_intl_breakiterator_fetch_object(zend_obj BREAKITER_METHOD_FETCH_OBJECT_NO_CHECK; \ if (bio->biter == NULL) \ { \ - intl_errors_set(&bio->err, U_ILLEGAL_ARGUMENT_ERROR, "Found unconstructed BreakIterator", 0); \ - RETURN_FALSE; \ + zend_throw_error(NULL, "Found unconstructed BreakIterator"); \ + RETURN_THROWS(); \ } void breakiterator_object_create(zval *object, BreakIterator *break_iter, int brand_new); diff --git a/ext/intl/calendar/calendar_class.h b/ext/intl/calendar/calendar_class.h index bd7ddf0aa92d3..a4d5236307e52 100644 --- a/ext/intl/calendar/calendar_class.h +++ b/ext/intl/calendar/calendar_class.h @@ -55,8 +55,8 @@ static inline Calendar_object *php_intl_calendar_fetch_object(zend_object *obj) CALENDAR_METHOD_FETCH_OBJECT_NO_CHECK; \ if (co->ucal == NULL) \ { \ - intl_errors_set(&co->err, U_ILLEGAL_ARGUMENT_ERROR, "Found unconstructed IntlCalendar", 0); \ - RETURN_FALSE; \ + zend_throw_error(NULL, "Found unconstructed IntlCalendar"); \ + RETURN_THROWS(); \ } void calendar_object_create(zval *object, Calendar *calendar); diff --git a/ext/intl/common/common_enum.h b/ext/intl/common/common_enum.h index f004b9be3766d..1f97575947b00 100644 --- a/ext/intl/common/common_enum.h +++ b/ext/intl/common/common_enum.h @@ -41,8 +41,8 @@ extern "C" { object = ZEND_THIS; \ INTLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK; \ if (ii->iterator == NULL) { \ - intl_errors_set(&ii->err, U_ILLEGAL_ARGUMENT_ERROR, "Found unconstructed IntlIterator", 0); \ - RETURN_FALSE; \ + zend_throw_error(NULL, "Found unconstructed IntlIterator"); \ + RETURN_THROWS(); \ } typedef struct { diff --git a/ext/intl/dateformat/dateformat_class.h b/ext/intl/dateformat/dateformat_class.h index 8a95527695068..dc060dbe84f39 100644 --- a/ext/intl/dateformat/dateformat_class.h +++ b/ext/intl/dateformat/dateformat_class.h @@ -46,8 +46,8 @@ extern zend_class_entry *IntlDateFormatter_ce_ptr; DATE_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK; \ if (dfo->datef_data.udatf == NULL) \ { \ - intl_errors_set(&dfo->datef_data.error, U_ILLEGAL_ARGUMENT_ERROR, "Found unconstructed IntlDateFormatter", 0); \ - RETURN_FALSE; \ + zend_throw_error(NULL, "Found unconstructed IntlDateFormatter"); \ + RETURN_THROWS(); \ } #define DATE_FORMAT_OBJECT(dfo) (dfo)->datef_data.udatf diff --git a/ext/intl/formatter/formatter_class.h b/ext/intl/formatter/formatter_class.h index 37b468d868069..b221a96ee46c8 100644 --- a/ext/intl/formatter/formatter_class.h +++ b/ext/intl/formatter/formatter_class.h @@ -44,9 +44,8 @@ extern zend_class_entry *NumberFormatter_ce_ptr; FORMATTER_METHOD_FETCH_OBJECT_NO_CHECK; \ if (FORMATTER_OBJECT(nfo) == NULL) \ { \ - intl_errors_set(&nfo->nf_data.error, U_ILLEGAL_ARGUMENT_ERROR, \ - "Found unconstructed NumberFormatter", 0); \ - RETURN_FALSE; \ + zend_throw_error(NULL, "Found unconstructed NumberFormatter"); \ + RETURN_THROWS(); \ } diff --git a/ext/intl/msgformat/msgformat_class.h b/ext/intl/msgformat/msgformat_class.h index 53028138437ef..2e0eda9d7e11b 100644 --- a/ext/intl/msgformat/msgformat_class.h +++ b/ext/intl/msgformat/msgformat_class.h @@ -46,9 +46,8 @@ extern zend_class_entry *MessageFormatter_ce_ptr; #define MSG_FORMAT_METHOD_FETCH_OBJECT \ MSG_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK; \ if (MSG_FORMAT_OBJECT(mfo) == NULL) { \ - intl_errors_set(&mfo->mf_data.error, U_ILLEGAL_ARGUMENT_ERROR, \ - "Found unconstructed MessageFormatter", 0); \ - RETURN_FALSE; \ + zend_throw_error(NULL, "Found unconstructed MessageFormatter"); \ + RETURN_THROWS(); \ } #define MSG_FORMAT_OBJECT(mfo) (mfo)->mf_data.umsgf diff --git a/ext/intl/resourcebundle/resourcebundle.stub.php b/ext/intl/resourcebundle/resourcebundle.stub.php index f3f0dcef1af76..14f10fea4bf9d 100644 --- a/ext/intl/resourcebundle/resourcebundle.stub.php +++ b/ext/intl/resourcebundle/resourcebundle.stub.php @@ -13,7 +13,7 @@ public static function create(?string $locale, ?string $bundlename, bool $fallba */ public function get($index, bool $fallback = true) {} - /** @return int|false */ + /** @return int */ public function count() {} /** @return array|false */ @@ -34,7 +34,7 @@ function resourcebundle_create(?string $locale, ?string $bundlename, bool $fallb */ function resourcebundle_get(ResourceBundle $bundle, $index) {} -function resourcebundle_count(ResourceBundle $bundle): int|false {} +function resourcebundle_count(ResourceBundle $bundle): int {} function resourcebundle_locales(string $bundlename): array|false {} diff --git a/ext/intl/resourcebundle/resourcebundle_arginfo.h b/ext/intl/resourcebundle/resourcebundle_arginfo.h index 9c4fbf088f68a..855b8b548c195 100644 --- a/ext/intl/resourcebundle/resourcebundle_arginfo.h +++ b/ext/intl/resourcebundle/resourcebundle_arginfo.h @@ -35,7 +35,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_resourcebundle_get, 0, 0, 2) ZEND_ARG_INFO(0, index) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_resourcebundle_count, 0, 1, MAY_BE_LONG|MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_resourcebundle_count, 0, 1, IS_LONG, 0) ZEND_ARG_OBJ_INFO(0, bundle, ResourceBundle, 0) ZEND_END_ARG_INFO() @@ -43,9 +43,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_resourcebundle_locales, 0, 1, MA ZEND_ARG_TYPE_INFO(0, bundlename, IS_STRING, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_resourcebundle_get_error_code, 0, 1, IS_LONG, 0) - ZEND_ARG_OBJ_INFO(0, bundle, ResourceBundle, 0) -ZEND_END_ARG_INFO() +#define arginfo_resourcebundle_get_error_code arginfo_resourcebundle_count ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_resourcebundle_get_error_message, 0, 1, IS_STRING, 0) ZEND_ARG_OBJ_INFO(0, bundle, ResourceBundle, 0) diff --git a/ext/intl/resourcebundle/resourcebundle_class.h b/ext/intl/resourcebundle/resourcebundle_class.h index c61939dc7740b..e7e264d66e626 100644 --- a/ext/intl/resourcebundle/resourcebundle_class.h +++ b/ext/intl/resourcebundle/resourcebundle_class.h @@ -38,14 +38,12 @@ static inline ResourceBundle_object *php_intl_resourcebundle_fetch_object(zend_o #define RESOURCEBUNDLE_METHOD_INIT_VARS INTL_METHOD_INIT_VARS(ResourceBundle, rb) #define RESOURCEBUNDLE_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(INTL_RESOURCEBUNDLE, rb) #define RESOURCEBUNDLE_METHOD_FETCH_OBJECT \ - INTL_METHOD_FETCH_OBJECT(INTL_RESOURCEBUNDLE, rb); \ + INTL_METHOD_FETCH_OBJECT(INTL_RESOURCEBUNDLE, rb); \ if (RESOURCEBUNDLE_OBJECT(rb) == NULL) { \ - intl_errors_set(&rb->error, U_ILLEGAL_ARGUMENT_ERROR, \ - "Found unconstructed ResourceBundle", 0); \ - RETURN_FALSE; \ + zend_throw_error(NULL, "Found unconstructed ResourceBundle"); \ + RETURN_THROWS(); \ } - #define RESOURCEBUNDLE_OBJECT(rb) (rb)->me void resourcebundle_register_class( void ); diff --git a/ext/intl/spoofchecker/spoofchecker.stub.php b/ext/intl/spoofchecker/spoofchecker.stub.php index 1609aa03c14a7..28c333cf692f4 100644 --- a/ext/intl/spoofchecker/spoofchecker.stub.php +++ b/ext/intl/spoofchecker/spoofchecker.stub.php @@ -10,14 +10,14 @@ public function isSuspicious(string $text, &$error = null) {} /** @return bool */ public function areConfusable(string $s1, string $s2, &$error = null) {} - /** @return null|false */ + /** @return void */ public function setAllowedLocales(string $locale_list) {} - /** @return null|false */ + /** @return void */ public function setChecks(int $checks) {} #if U_ICU_VERSION_MAJOR_NUM >= 58 - /** @return null|false */ + /** @return void */ public function setRestrictionLevel(int $level) {} #endif } diff --git a/ext/intl/spoofchecker/spoofchecker_class.h b/ext/intl/spoofchecker/spoofchecker_class.h index b8b0e5e287d4c..12593e35bebe1 100644 --- a/ext/intl/spoofchecker/spoofchecker_class.h +++ b/ext/intl/spoofchecker/spoofchecker_class.h @@ -63,9 +63,8 @@ extern zend_class_entry *Spoofchecker_ce_ptr; #define SPOOFCHECKER_METHOD_FETCH_OBJECT \ SPOOFCHECKER_METHOD_FETCH_OBJECT_NO_CHECK; \ if (co->uspoof == NULL) { \ - intl_errors_set(&co->err, U_ILLEGAL_ARGUMENT_ERROR, \ - "Found unconstructed Spoofchecker", 0); \ - RETURN_FALSE; \ + zend_throw_error(NULL, "Found unconstructed Spoofchecker"); \ + RETURN_THROWS(); \ } // Macro to check return value of a ucol_* function call. diff --git a/ext/intl/tests/symfony_format_type_double_intl1.phpt b/ext/intl/tests/symfony_format_type_double_intl1.phpt index 13a7ad761fa77..9a5c6b2a25893 100644 --- a/ext/intl/tests/symfony_format_type_double_intl1.phpt +++ b/ext/intl/tests/symfony_format_type_double_intl1.phpt @@ -12,11 +12,11 @@ $unit_test_args = unserialize('a:3:{i:0;O:15:"NumberFormatter":0:{}i:1;i:1;i:2;s var_dump($unit_test_args); // execute the code from #testFormatTypeDoubleIntl -$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_DOUBLE); - -echo "== didn't crash ==".PHP_EOL; - -?> +try { + $unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_DOUBLE); +} catch (Error $exception) { + echo $exception->getMessage() . "\n"; +} --EXPECT-- array(3) { [0]=> @@ -27,4 +27,4 @@ array(3) { [2]=> string(1) "1" } -== didn't crash == +Found unconstructed NumberFormatter diff --git a/ext/intl/tests/symfony_format_type_double_intl2.phpt b/ext/intl/tests/symfony_format_type_double_intl2.phpt index 6bff7cc3557c0..e5014c6f34db1 100644 --- a/ext/intl/tests/symfony_format_type_double_intl2.phpt +++ b/ext/intl/tests/symfony_format_type_double_intl2.phpt @@ -12,11 +12,11 @@ $unit_test_args = unserialize('a:3:{i:0;O:15:"NumberFormatter":0:{}i:1;d:1.10000 var_dump($unit_test_args); // execute the code from #testFormatTypeDoubleIntl -$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_DOUBLE); - -echo "== didn't crash ==".PHP_EOL; - -?> +try { + $unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_DOUBLE); +} catch (Error $exception) { + echo $exception->getMessage() . "\n"; +} --EXPECT-- array(3) { [0]=> @@ -27,4 +27,4 @@ array(3) { [2]=> string(3) "1.1" } -== didn't crash == +Found unconstructed NumberFormatter diff --git a/ext/intl/tests/symfony_format_type_double_intl3.phpt b/ext/intl/tests/symfony_format_type_double_intl3.phpt index 3b0d576df7d47..fbfd629b75a92 100644 --- a/ext/intl/tests/symfony_format_type_double_intl3.phpt +++ b/ext/intl/tests/symfony_format_type_double_intl3.phpt @@ -12,11 +12,11 @@ $unit_test_args = unserialize('a:3:{i:0;O:15:"NumberFormatter":0:{}i:1;i:1;i:2;s var_dump($unit_test_args); // execute the code from #testFormatTypeDoubleIntl -$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_DOUBLE); - -echo "== didn't crash ==".PHP_EOL; - -?> +try { + $unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_DOUBLE); +} catch (Error $exception) { + echo $exception->getMessage() . "\n"; +} --EXPECT-- array(3) { [0]=> @@ -27,4 +27,4 @@ array(3) { [2]=> string(7) "SFD1.00" } -== didn't crash == +Found unconstructed NumberFormatter diff --git a/ext/intl/tests/symfony_format_type_double_intl4.phpt b/ext/intl/tests/symfony_format_type_double_intl4.phpt index 3476e108923d9..b736c23dab31b 100644 --- a/ext/intl/tests/symfony_format_type_double_intl4.phpt +++ b/ext/intl/tests/symfony_format_type_double_intl4.phpt @@ -12,10 +12,11 @@ $unit_test_args = unserialize('a:3:{i:0;O:15:"NumberFormatter":0:{}i:1;d:1.10000 var_dump($unit_test_args); // execute the code from #testFormatTypeDoubleIntl -$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_DOUBLE); - -echo "== didn't crash ==".PHP_EOL; - +try { + $unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_DOUBLE); +} catch (Error $exception) { + echo $exception->getMessage() . "\n"; +} ?> --EXPECT-- array(3) { @@ -27,4 +28,4 @@ array(3) { [2]=> string(7) "SFD1.10" } -== didn't crash == +Found unconstructed NumberFormatter diff --git a/ext/intl/tests/symfony_format_type_int32_intl1.phpt b/ext/intl/tests/symfony_format_type_int32_intl1.phpt index 7d892cf5b6eb8..717414fc6f16f 100644 --- a/ext/intl/tests/symfony_format_type_int32_intl1.phpt +++ b/ext/intl/tests/symfony_format_type_int32_intl1.phpt @@ -31,11 +31,11 @@ $unit_test_args = unserialize('a:3:{i:0;O:15:"NumberFormatter":0:{}i:1;i:1;i:2;s var_dump($unit_test_args); // execute the code from #testFormatTypeInt32Intl -$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT32); - -echo "== didn't crash ==".PHP_EOL; - -?> +try { + $unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT32); +} catch (Error $exception) { + echo $exception->getMessage() . "\n"; +} --EXPECT-- array(3) { [0]=> @@ -46,4 +46,4 @@ array(3) { [2]=> string(1) "1" } -== didn't crash == +Found unconstructed NumberFormatter diff --git a/ext/intl/tests/symfony_format_type_int32_intl2.phpt b/ext/intl/tests/symfony_format_type_int32_intl2.phpt index 6a65a0a809241..4b84ec1979281 100644 --- a/ext/intl/tests/symfony_format_type_int32_intl2.phpt +++ b/ext/intl/tests/symfony_format_type_int32_intl2.phpt @@ -15,11 +15,11 @@ $unit_test_args = unserialize('a:3:{i:0;O:15:"NumberFormatter":0:{}i:1;d:1.10000 var_dump($unit_test_args); // execute the code from #testFormatTypeInt32Intl -$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT32); - -echo "== didn't crash ==".PHP_EOL; - -?> +try { + $unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT32); +} catch (Error $exception) { + echo $exception->getMessage() . "\n"; +} --EXPECT-- array(3) { [0]=> @@ -30,4 +30,4 @@ array(3) { [2]=> string(1) "1" } -== didn't crash == +Found unconstructed NumberFormatter diff --git a/ext/intl/tests/symfony_format_type_int32_intl3.phpt b/ext/intl/tests/symfony_format_type_int32_intl3.phpt index 5e657db419b9d..efe35dd8b01b0 100644 --- a/ext/intl/tests/symfony_format_type_int32_intl3.phpt +++ b/ext/intl/tests/symfony_format_type_int32_intl3.phpt @@ -12,11 +12,11 @@ $unit_test_args = unserialize('a:4:{i:0;O:15:"NumberFormatter":0:{}i:1;d:2147483 var_dump($unit_test_args); // execute the code from #testFormatTypeInt32Intl -$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT32); - -echo "== didn't crash ==".PHP_EOL; - -?> +try { + $unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT32); +} catch (Error $exception) { + echo $exception->getMessage() . "\n"; +} --EXPECT-- array(4) { [0]=> @@ -29,4 +29,4 @@ array(4) { [3]=> string(83) "->format() TYPE_INT32 formats inconsistently an integer if out of the 32 bit range." } -== didn't crash == +Found unconstructed NumberFormatter diff --git a/ext/intl/tests/symfony_format_type_int32_intl4.phpt b/ext/intl/tests/symfony_format_type_int32_intl4.phpt index 54043d92e921b..8f6ea7b0c0594 100644 --- a/ext/intl/tests/symfony_format_type_int32_intl4.phpt +++ b/ext/intl/tests/symfony_format_type_int32_intl4.phpt @@ -12,11 +12,11 @@ $unit_test_args = unserialize('a:3:{i:0;O:15:"NumberFormatter":0:{}i:1;i:1;i:2;s var_dump($unit_test_args); // execute the code from #testFormatTypeInt32Intl -$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT32); - -echo "== didn't crash ==".PHP_EOL; - -?> +try { + $unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT32); +} catch (Error $exception) { + echo $exception->getMessage() . "\n"; +} --EXPECT-- array(3) { [0]=> @@ -27,4 +27,4 @@ array(3) { [2]=> string(7) "SFD1.00" } -== didn't crash == +Found unconstructed NumberFormatter diff --git a/ext/intl/tests/symfony_format_type_int32_intl5.phpt b/ext/intl/tests/symfony_format_type_int32_intl5.phpt index d5f78d7119bcf..b9d302a12f250 100644 --- a/ext/intl/tests/symfony_format_type_int32_intl5.phpt +++ b/ext/intl/tests/symfony_format_type_int32_intl5.phpt @@ -12,11 +12,11 @@ $unit_test_args = unserialize('a:3:{i:0;O:15:"NumberFormatter":0:{}i:1;d:1.10000 var_dump($unit_test_args); // execute the code from #testFormatTypeInt32Intl -$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT32); - -echo "== didn't crash ==".PHP_EOL; - -?> +try { + $unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT32); +} catch (Error $exception) { + echo $exception->getMessage() . "\n"; +} --EXPECT-- array(3) { [0]=> @@ -27,4 +27,4 @@ array(3) { [2]=> string(7) "SFD1.00" } -== didn't crash == +Found unconstructed NumberFormatter diff --git a/ext/intl/tests/symfony_format_type_int32_intl6.phpt b/ext/intl/tests/symfony_format_type_int32_intl6.phpt index fa708799d1310..b00f3f7ce9480 100644 --- a/ext/intl/tests/symfony_format_type_int32_intl6.phpt +++ b/ext/intl/tests/symfony_format_type_int32_intl6.phpt @@ -12,11 +12,11 @@ $unit_test_args = unserialize('a:4:{i:0;O:15:"NumberFormatter":0:{}i:1;d:2147483 var_dump($unit_test_args); // execute the code from #testFormatTypeInt32Intl -$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT32); - -echo "== didn't crash ==".PHP_EOL; - -?> +try { + $unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT32); +} catch (Error $exception) { + echo $exception->getMessage() . "\n"; +} --EXPECT-- array(4) { [0]=> @@ -29,4 +29,4 @@ array(4) { [3]=> string(83) "->format() TYPE_INT32 formats inconsistently an integer if out of the 32 bit range." } -== didn't crash == +Found unconstructed NumberFormatter diff --git a/ext/intl/tests/symfony_format_type_int32_intl7.phpt b/ext/intl/tests/symfony_format_type_int32_intl7.phpt index 5bbe4266770a0..747074f090665 100644 --- a/ext/intl/tests/symfony_format_type_int32_intl7.phpt +++ b/ext/intl/tests/symfony_format_type_int32_intl7.phpt @@ -12,11 +12,11 @@ $unit_test_args = unserialize('a:4:{i:0;O:15:"NumberFormatter":0:{}i:1;d:-214748 var_dump($unit_test_args); // execute the code from #testFormatTypeInt32Intl -$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT32); - -echo "== didn't crash ==".PHP_EOL; - -?> +try { + $unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT32); +} catch (Error $exception) { + echo $exception->getMessage() . "\n"; +} --EXPECT-- array(4) { [0]=> @@ -29,4 +29,4 @@ array(4) { [3]=> string(83) "->format() TYPE_INT32 formats inconsistently an integer if out of the 32 bit range." } -== didn't crash == +Found unconstructed NumberFormatter diff --git a/ext/intl/tests/symfony_format_type_int64_intl2.phpt b/ext/intl/tests/symfony_format_type_int64_intl2.phpt index 13d1cdaee7f37..f659ac373d516 100644 --- a/ext/intl/tests/symfony_format_type_int64_intl2.phpt +++ b/ext/intl/tests/symfony_format_type_int64_intl2.phpt @@ -12,11 +12,11 @@ $unit_test_args = unserialize('a:3:{i:0;O:15:"NumberFormatter":0:{}i:1;d:1.10000 var_dump($unit_test_args); // execute the code from #testFormatTypeInt64Intl -$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT64); - -echo "== didn't crash ==".PHP_EOL; - -?> +try { + $unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT64); +} catch (Error $exception) { + echo $exception->getMessage() . "\n"; +} --EXPECT-- array(3) { [0]=> @@ -27,4 +27,4 @@ array(3) { [2]=> string(1) "1" } -== didn't crash == +Found unconstructed NumberFormatter diff --git a/ext/intl/tests/symfony_format_type_int64_intl3.phpt b/ext/intl/tests/symfony_format_type_int64_intl3.phpt index a7c80b34c3cf5..e40b74775c6ea 100644 --- a/ext/intl/tests/symfony_format_type_int64_intl3.phpt +++ b/ext/intl/tests/symfony_format_type_int64_intl3.phpt @@ -12,11 +12,11 @@ $unit_test_args = unserialize('a:3:{i:0;O:15:"NumberFormatter":0:{}i:1;d:2147483 var_dump($unit_test_args); // execute the code from #testFormatTypeInt64Intl -$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT64); - -echo "== didn't crash ==".PHP_EOL; - -?> +try { + $unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT64); +} catch (Error $exception) { + echo $exception->getMessage() . "\n"; +} --EXPECT-- array(3) { [0]=> @@ -27,4 +27,4 @@ array(3) { [2]=> string(13) "2,147,483,648" } -== didn't crash == +Found unconstructed NumberFormatter diff --git a/ext/intl/tests/symfony_format_type_int64_intl4.phpt b/ext/intl/tests/symfony_format_type_int64_intl4.phpt index f1a0801edfe97..8785b83c0adae 100644 --- a/ext/intl/tests/symfony_format_type_int64_intl4.phpt +++ b/ext/intl/tests/symfony_format_type_int64_intl4.phpt @@ -12,11 +12,11 @@ $unit_test_args = unserialize('a:3:{i:0;O:15:"NumberFormatter":0:{}i:1;d:-214748 var_dump($unit_test_args); // execute the code from #testFormatTypeInt64Intl -$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT64); - -echo "== didn't crash ==".PHP_EOL; - -?> +try { + $unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT64); +} catch (Error $exception) { + echo $exception->getMessage() . "\n"; +} --EXPECT-- array(3) { [0]=> @@ -27,4 +27,4 @@ array(3) { [2]=> string(14) "-2,147,483,649" } -== didn't crash == +Found unconstructed NumberFormatter diff --git a/ext/intl/tests/symfony_format_type_int64_intl5.phpt b/ext/intl/tests/symfony_format_type_int64_intl5.phpt index dad8735b89a3c..476e66b61ea51 100644 --- a/ext/intl/tests/symfony_format_type_int64_intl5.phpt +++ b/ext/intl/tests/symfony_format_type_int64_intl5.phpt @@ -12,11 +12,11 @@ $unit_test_args = unserialize('a:3:{i:0;O:15:"NumberFormatter":0:{}i:1;i:1;i:2;s var_dump($unit_test_args); // execute the code from #testFormatTypeInt64Intl -$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT64); - -echo "== didn't crash ==".PHP_EOL; - -?> +try { + $unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT64); +} catch (Error $exception) { + echo $exception->getMessage() . "\n"; +} --EXPECT-- array(3) { [0]=> @@ -27,4 +27,4 @@ array(3) { [2]=> string(7) "SFD1.00" } -== didn't crash == +Found unconstructed NumberFormatter diff --git a/ext/intl/tests/symfony_format_type_int64_intl6.phpt b/ext/intl/tests/symfony_format_type_int64_intl6.phpt index f038cbd0c3cad..5c24fe9617a07 100644 --- a/ext/intl/tests/symfony_format_type_int64_intl6.phpt +++ b/ext/intl/tests/symfony_format_type_int64_intl6.phpt @@ -12,11 +12,11 @@ $unit_test_args = unserialize('a:3:{i:0;O:15:"NumberFormatter":0:{}i:1;d:1.10000 var_dump($unit_test_args); // execute the code from #testFormatTypeInt64Intl -$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT64); - -echo "== didn't crash ==".PHP_EOL; - -?> +try { + $unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT64); +} catch (Error $exception) { + echo $exception->getMessage() . "\n"; +} --EXPECT-- array(3) { [0]=> @@ -27,4 +27,4 @@ array(3) { [2]=> string(7) "SFD1.00" } -== didn't crash == +Found unconstructed NumberFormatter diff --git a/ext/intl/tests/symfony_format_type_int64_intl7.phpt b/ext/intl/tests/symfony_format_type_int64_intl7.phpt index 9c8853cafc82a..27b5a79f24d0d 100644 --- a/ext/intl/tests/symfony_format_type_int64_intl7.phpt +++ b/ext/intl/tests/symfony_format_type_int64_intl7.phpt @@ -12,11 +12,11 @@ $unit_test_args = unserialize('a:3:{i:0;O:15:"NumberFormatter":0:{}i:1;d:2147483 var_dump($unit_test_args); // execute the code from #testFormatTypeInt64Intl -$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT64); - -echo "== didn't crash ==".PHP_EOL; - -?> +try { + $unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT64); +} catch (Error $exception) { + echo $exception->getMessage() . "\n"; +} --EXPECT-- array(3) { [0]=> @@ -27,4 +27,4 @@ array(3) { [2]=> string(19) "SFD2,147,483,648.00" } -== didn't crash == +Found unconstructed NumberFormatter diff --git a/ext/intl/tests/symfony_format_type_int64_intl8.phpt b/ext/intl/tests/symfony_format_type_int64_intl8.phpt index 50524976abf15..d33395d6b3059 100644 --- a/ext/intl/tests/symfony_format_type_int64_intl8.phpt +++ b/ext/intl/tests/symfony_format_type_int64_intl8.phpt @@ -12,11 +12,11 @@ $unit_test_args = unserialize('a:3:{i:0;O:15:"NumberFormatter":0:{}i:1;d:-214748 var_dump($unit_test_args); // execute the code from #testFormatTypeInt64Intl -$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT64); - -echo "== didn't crash ==".PHP_EOL; - -?> +try { + $unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT64); +} catch (Error $exception) { + echo $exception->getMessage() . "\n"; +} --EXPECT-- array(3) { [0]=> @@ -27,4 +27,4 @@ array(3) { [2]=> string(21) "(SFD2,147,483,649.00)" } -== didn't crash == +Found unconstructed NumberFormatter diff --git a/ext/intl/timezone/timezone.stub.php b/ext/intl/timezone/timezone.stub.php index 06f5424aa4c5d..332fb9c1d2b33 100644 --- a/ext/intl/timezone/timezone.stub.php +++ b/ext/intl/timezone/timezone.stub.php @@ -31,7 +31,7 @@ public static function getCanonicalID(string $zoneId, &$isSystemID = null) {} /** @return string|false */ public function getDisplayName(bool $isDaylight = false, int $style = IntlTimeZone::DISPLAY_LONG, ?string $locale = null) {} - /** @return int|false */ + /** @return int */ public function getDSTSavings() {} /** @return string|false */ @@ -52,7 +52,7 @@ public function getID() {} /** @return bool */ public function getOffset(float $date, bool $local, &$rawOffset, &$dstOffset) {} - /** @return int|false */ + /** @return int */ public function getRawOffset() {} /** @return string|false */ @@ -101,7 +101,7 @@ function intltz_get_canonical_id(string $zoneId, &$isSystemID = null): string|fa function intltz_get_display_name(IntlTimeZone $tz, bool $isDaylight = false, int $style = IntlTimeZone::DISPLAY_LONG, ?string $locale = null): string|false {} -function intltz_get_dst_savings(IntlTimeZone $tz): int|false {} +function intltz_get_dst_savings(IntlTimeZone $tz): int {} function intltz_get_equivalent_id(string $zoneId, int $index): string|false {} @@ -115,7 +115,7 @@ function intltz_get_id(IntlTimeZone $tz): string|false {} function intltz_get_offset(IntlTimeZone $tz, float $date, bool $local, &$rawOffset, &$dstOffset): bool {} -function intltz_get_raw_offset(IntlTimeZone $tz): int|false {} +function intltz_get_raw_offset(IntlTimeZone $tz): int {} function intltz_get_region(string $zoneId): string|false {} diff --git a/ext/intl/timezone/timezone_arginfo.h b/ext/intl/timezone/timezone_arginfo.h index 8cf82ef56a62e..94c79627813fd 100644 --- a/ext/intl/timezone/timezone_arginfo.h +++ b/ext/intl/timezone/timezone_arginfo.h @@ -122,7 +122,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_intltz_get_display_name, 0, 1, M ZEND_ARG_TYPE_INFO(0, locale, IS_STRING, 1) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_intltz_get_dst_savings, 0, 1, MAY_BE_LONG|MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_intltz_get_dst_savings, 0, 1, IS_LONG, 0) ZEND_ARG_OBJ_INFO(0, tz, IntlTimeZone, 0) ZEND_END_ARG_INFO() @@ -131,7 +131,9 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_intltz_get_equivalent_id, 0, 2, ZEND_ARG_TYPE_INFO(0, index, IS_LONG, 0) ZEND_END_ARG_INFO() -#define arginfo_intltz_get_error_code arginfo_intltz_get_dst_savings +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_intltz_get_error_code, 0, 1, MAY_BE_LONG|MAY_BE_FALSE) + ZEND_ARG_OBJ_INFO(0, tz, IntlTimeZone, 0) +ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_intltz_get_error_message, 0, 1, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_OBJ_INFO(0, tz, IntlTimeZone, 0) diff --git a/ext/intl/timezone/timezone_class.h b/ext/intl/timezone/timezone_class.h index f0fd5cdee812e..8fe4524415ebd 100644 --- a/ext/intl/timezone/timezone_class.h +++ b/ext/intl/timezone/timezone_class.h @@ -60,8 +60,8 @@ static inline TimeZone_object *php_intl_timezone_fetch_object(zend_object *obj) #define TIMEZONE_METHOD_FETCH_OBJECT\ TIMEZONE_METHOD_FETCH_OBJECT_NO_CHECK; \ if (to->utimezone == NULL) { \ - intl_errors_set(&to->err, U_ILLEGAL_ARGUMENT_ERROR, "Found unconstructed IntlTimeZone", 0); \ - RETURN_FALSE; \ + zend_throw_error(NULL, "Found unconstructed IntlTimeZone"); \ + RETURN_THROWS(); \ } zval *timezone_convert_to_datetimezone(const TimeZone *timeZone, intl_error *outside_error, const char *func, zval *ret); diff --git a/ext/intl/transliterator/transliterator_class.h b/ext/intl/transliterator/transliterator_class.h index 98f599c81b50a..907ad79c44f70 100644 --- a/ext/intl/transliterator/transliterator_class.h +++ b/ext/intl/transliterator/transliterator_class.h @@ -52,8 +52,8 @@ static inline Transliterator_object *php_intl_transliterator_fetch_object(zend_o TRANSLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK; \ if( to->utrans == NULL ) \ { \ - intl_errors_set( &to->err, U_ILLEGAL_ARGUMENT_ERROR, "Found unconstructed transliterator", 0 ); \ - RETURN_FALSE; \ + zend_throw_error(NULL, "Found unconstructed transliterator"); \ + RETURN_THROWS(); \ } int transliterator_object_construct( zval *object,