From 660e9fe9f599fcaa241e7eb83662a7503bb57890 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Fri, 5 Jun 2020 17:42:08 +0200 Subject: [PATCH 1/8] Promote some IntlBreakIterator internal error handling to standard ValueError --- ext/intl/breakiterator/breakiterator.stub.php | 8 ++-- .../breakiterator/breakiterator_methods.cpp | 43 +++++++------------ .../breakiter_getPartsIterator_error.phpt | 13 +++--- 3 files changed, 28 insertions(+), 36 deletions(-) diff --git a/ext/intl/breakiterator/breakiterator.stub.php b/ext/intl/breakiterator/breakiterator.stub.php index 341e9df1f3569..fda35217dfcb2 100644 --- a/ext/intl/breakiterator/breakiterator.stub.php +++ b/ext/intl/breakiterator/breakiterator.stub.php @@ -30,7 +30,7 @@ public function current() {} /** @return int */ public function first() {} - /** @return int|false */ + /** @return int */ public function following(int $offset) {} /** @return int */ @@ -42,7 +42,7 @@ public function getErrorMessage() {} /** @return string */ public function getLocale(int $locale_type) {} - /** @return IntlPartsIterator|false */ + /** @return IntlPartsIterator */ public function getPartsIterator(string $key_type = IntlPartsIterator::KEY_SEQUENTIAL) {} /** @return string|null */ @@ -54,10 +54,10 @@ public function isBoundary(int $offset) {} /** @return int */ public function last() {} - /** @return int|false */ + /** @return int */ public function next(?int $offset = null) {} - /** @return int|false */ + /** @return int */ public function preceding(int $offset) {} /** @return int */ diff --git a/ext/intl/breakiterator/breakiterator_methods.cpp b/ext/intl/breakiterator/breakiterator_methods.cpp index 393290b66e5d9..c389fe80ef9fa 100644 --- a/ext/intl/breakiterator/breakiterator_methods.cpp +++ b/ext/intl/breakiterator/breakiterator_methods.cpp @@ -63,6 +63,7 @@ static void _breakiter_factory(const char *func_name, biter = func(Locale::createFromName(locale_str), status); intl_error_set_code(NULL, status); + // Todo check if this can happen? if (U_FAILURE(status)) { spprintf(&msg, 0, "%s: error creating BreakIterator", func_name); @@ -170,7 +171,6 @@ U_CFUNC PHP_METHOD(IntlBreakIterator, setText) } static void _breakiter_no_args_ret_int32( - const char *func_name, int32_t (BreakIterator::*func)(), INTERNAL_FUNCTION_PARAMETERS) { @@ -190,11 +190,9 @@ static void _breakiter_no_args_ret_int32( } static void _breakiter_int32_ret_int32( - const char *func_name, int32_t (BreakIterator::*func)(int32_t), INTERNAL_FUNCTION_PARAMETERS) { - char *msg; zend_long arg; BREAKITER_METHOD_INIT_VARS; object = ZEND_THIS; @@ -206,11 +204,8 @@ static void _breakiter_int32_ret_int32( BREAKITER_METHOD_FETCH_OBJECT; if (arg < INT32_MIN || arg > INT32_MAX) { - spprintf(&msg, 0, "%s: offset argument is outside bounds of " - "a 32-bit wide integer", func_name); - intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, msg, 1); - efree(msg); - RETURN_FALSE; + zend_argument_value_error(1, "must be between %d and %d", INT32_MIN, INT32_MAX); + RETURN_THROWS(); } int32_t res = (bio->biter->*func)((int32_t)arg); @@ -220,22 +215,19 @@ static void _breakiter_int32_ret_int32( U_CFUNC PHP_METHOD(IntlBreakIterator, first) { - _breakiter_no_args_ret_int32("breakiter_first", - &BreakIterator::first, + _breakiter_no_args_ret_int32(&BreakIterator::first, INTERNAL_FUNCTION_PARAM_PASSTHRU); } U_CFUNC PHP_METHOD(IntlBreakIterator, last) { - _breakiter_no_args_ret_int32("breakiter_last", - &BreakIterator::last, + _breakiter_no_args_ret_int32(&BreakIterator::last, INTERNAL_FUNCTION_PARAM_PASSTHRU); } U_CFUNC PHP_METHOD(IntlBreakIterator, previous) { - _breakiter_no_args_ret_int32("breakiter_previous", - &BreakIterator::previous, + _breakiter_no_args_ret_int32(&BreakIterator::previous, INTERNAL_FUNCTION_PARAM_PASSTHRU); } @@ -253,12 +245,10 @@ U_CFUNC PHP_METHOD(IntlBreakIterator, next) if (arg == NULL) { ZEND_NUM_ARGS() = 0; /* pretend we don't have any argument */ no_arg_version: - _breakiter_no_args_ret_int32("breakiter_next", - &BreakIterator::next, + _breakiter_no_args_ret_int32(&BreakIterator::next, INTERNAL_FUNCTION_PARAM_PASSTHRU); } else { - _breakiter_int32_ret_int32("breakiter_next", - &BreakIterator::next, + _breakiter_int32_ret_int32(&BreakIterator::next, INTERNAL_FUNCTION_PARAM_PASSTHRU); } } @@ -281,14 +271,14 @@ U_CFUNC PHP_METHOD(IntlBreakIterator, current) U_CFUNC PHP_METHOD(IntlBreakIterator, following) { - _breakiter_int32_ret_int32("breakiter_following", + _breakiter_int32_ret_int32( &BreakIterator::following, INTERNAL_FUNCTION_PARAM_PASSTHRU); } U_CFUNC PHP_METHOD(IntlBreakIterator, preceding) { - _breakiter_int32_ret_int32("breakiter_preceding", + _breakiter_int32_ret_int32( &BreakIterator::preceding, INTERNAL_FUNCTION_PARAM_PASSTHRU); } @@ -305,10 +295,8 @@ U_CFUNC PHP_METHOD(IntlBreakIterator, isBoundary) } if (offset < INT32_MIN || offset > INT32_MAX) { - intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, - "breakiter_is_boundary: offset argument is outside bounds of " - "a 32-bit wide integer", 0); - RETURN_FALSE; + zend_argument_value_error(1, "must be between %d and %d", INT32_MIN, INT32_MAX); + RETURN_THROWS(); } BREAKITER_METHOD_FETCH_OBJECT; @@ -328,6 +316,7 @@ U_CFUNC PHP_METHOD(IntlBreakIterator, getLocale) RETURN_THROWS(); } + /* Change to ValueError? */ if (locale_type != ULOC_ACTUAL_LOCALE && locale_type != ULOC_VALID_LOCALE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "breakiter_get_locale: invalid locale type", 0); @@ -357,9 +346,9 @@ U_CFUNC PHP_METHOD(IntlBreakIterator, getPartsIterator) if (key_type != PARTS_ITERATOR_KEY_SEQUENTIAL && key_type != PARTS_ITERATOR_KEY_LEFT && key_type != PARTS_ITERATOR_KEY_RIGHT) { - intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, - "breakiter_get_parts_iterator: bad key type", 0); - RETURN_FALSE; + zend_argument_value_error(1, "must be one of IntlPartsIterator::KEY_SEQUENTIAL, " + "IntlPartsIterator::KEY_LEFT, or IntlPartsIterator::KEY_RIGHT"); + RETURN_THROWS(); } BREAKITER_METHOD_FETCH_OBJECT; diff --git a/ext/intl/tests/breakiter_getPartsIterator_error.phpt b/ext/intl/tests/breakiter_getPartsIterator_error.phpt index b2931a000d7de..f86e64d4ccdd7 100644 --- a/ext/intl/tests/breakiter_getPartsIterator_error.phpt +++ b/ext/intl/tests/breakiter_getPartsIterator_error.phpt @@ -6,13 +6,16 @@ if (!extension_loaded('intl')) die('skip intl extension not enabled'); --FILE-- getPartsIterator(-1)); + +try { + var_dump($it->getPartsIterator(-1)); +} catch(\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} ?> ---EXPECTF-- -Warning: IntlBreakIterator::getPartsIterator(): breakiter_get_parts_iterator: bad key type in %s on line %d -bool(false) +--EXPECT-- +IntlBreakIterator::getPartsIterator(): Argument #1 ($key_type) must be one of IntlPartsIterator::KEY_SEQUENTIAL, IntlPartsIterator::KEY_LEFT, or IntlPartsIterator::KEY_RIGHT From 65f2db69191b630585992047cce804a19e3aee92 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Fri, 5 Jun 2020 19:53:10 +0200 Subject: [PATCH 2/8] Convert some internal IntlCalendar warnigns to Errors --- .../breakiterator/breakiterator_arginfo.h | 2 +- ext/intl/calendar/calendar.stub.php | 30 ++-- ext/intl/calendar/calendar_arginfo.h | 2 +- ext/intl/calendar/calendar_methods.cpp | 156 +++++++----------- ext/intl/php_intl.stub.php | 30 ++-- ext/intl/php_intl_arginfo.h | 26 +-- ext/intl/tests/calendar_clear_error.phpt | 35 ++-- .../calendar_getDayOfWeekType_error.phpt | 25 +-- .../calendar_getWeekendTransition_error.phpt | 24 +-- ..._Least_Greatest_Minimum_Maximum_error.phpt | 112 +++++++------ ...ar_get_getActualMaximum_Minumum_error.phpt | 32 ++-- ...r_get_getActualMaximum_Minumum_error2.phpt | 89 ++++------ ext/intl/tests/calendar_isSet_error.phpt | 24 +-- ext/intl/tests/calendar_roll_error.phpt | 23 +-- .../calendar_setFirstDayOfWeek_error.phpt | 34 ++-- ...endar_setMinimalDaysInFirstWeek_error.phpt | 34 ++-- ...tSkipped_RepeatedWallTimeOption_error.phpt | 34 ++-- ext/intl/tests/calendar_set_error.phpt | 38 +++-- 18 files changed, 370 insertions(+), 380 deletions(-) diff --git a/ext/intl/breakiterator/breakiterator_arginfo.h b/ext/intl/breakiterator/breakiterator_arginfo.h index 98a22a4dde8c0..ee0d3fc27dc63 100644 --- a/ext/intl/breakiterator/breakiterator_arginfo.h +++ b/ext/intl/breakiterator/breakiterator_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 7180c7b167edb3aa8580ae4a600627f28636ac38 */ + * Stub hash: 5eeedbbb7d07b0063d7bc19842b863a2c6d6898b */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_IntlBreakIterator_createCharacterInstance, 0, 0, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, locale, IS_STRING, 1, "null") diff --git a/ext/intl/calendar/calendar.stub.php b/ext/intl/calendar/calendar.stub.php index d704ab77c9346..d3a7958ee94c8 100644 --- a/ext/intl/calendar/calendar.stub.php +++ b/ext/intl/calendar/calendar.stub.php @@ -20,7 +20,7 @@ public static function createInstance($timeZone = null, ?string $locale = null) public function equals(IntlCalendar $calendar) {} /** - * @return int|false + * @return int * @alias intlcal_field_difference */ public function fieldDifference(float $when, int $field) {} @@ -57,19 +57,19 @@ public function clear(?int $field = null) {} public static function fromDateTime($dateTime, ?string $locale = null) {} /** - * @return int|false + * @return int * @alias intlcal_get */ public function get(int $field) {} /** - * @return int|false + * @return int * @alias intlcal_get_actual_maximum */ public function getActualMaximum(int $field) {} /** - * @return int|false + * @return int * @alias intlcal_get_actual_minimum */ public function getActualMinimum(int $field) {} @@ -81,7 +81,7 @@ public function getActualMinimum(int $field) {} public static function getAvailableLocales() {} /** - * @return int|false + * @return int * @alias intlcal_get_day_of_week_type */ public function getDayOfWeekType(int $dayOfWeek) {} @@ -99,13 +99,13 @@ public function getErrorCode() {} public function getErrorMessage() {} /** - * @return int|false + * @return int * @alias intlcal_get_first_day_of_week */ public function getFirstDayOfWeek() {} /** - * @return int|false + * @return int * @alias intlcal_get_greatest_minimum */ public function getGreatestMinimum(int $field) {} @@ -117,25 +117,25 @@ public function getGreatestMinimum(int $field) {} public static function getKeywordValuesForLocale(string $key, string $locale, bool $commonlyUsed) {} /** - * @return int|false + * @return int * @alias intlcal_get_least_maximum */ public function getLeastMaximum(int $field) {} /** - * @return string|false + * @return string * @alias intlcal_get_locale */ public function getLocale(int $localeType) {} /** - * @return int|false + * @return int * @alias intlcal_get_maximum */ public function getMaximum(int $field) {} /** - * @return int|false + * @return int * @alias intlcal_get_minimal_days_in_first_week */ public function getMinimalDaysInFirstWeek() {} @@ -147,7 +147,7 @@ public function getMinimalDaysInFirstWeek() {} public function setMinimalDaysInFirstWeek(int $numberOfDays) {} /** - * @return int|false + * @return int * @alias intlcal_get_minimum */ public function getMinimum(int $field) {} @@ -171,7 +171,7 @@ public function getRepeatedWallTimeOption() {} public function getSkippedWallTimeOption() {} /** - * @return float|false + * @return float * @alias intlcal_get_time */ public function getTime() {} @@ -189,7 +189,7 @@ public function getTimeZone() {} public function getType() {} /** - * @return int|false + * @return int * @alias intlcal_get_weekend_transition */ public function getWeekendTransition(int $dayOfWeek) {} @@ -292,7 +292,7 @@ public function __construct($timeZoneOrYear = UNKNOWN, $localeOrMonth = UNKNOWN, public function setGregorianChange(float $change) {} /** - * @return float|false + * @return float * @alias intlgregcal_get_gregorian_change */ public function getGregorianChange() {} diff --git a/ext/intl/calendar/calendar_arginfo.h b/ext/intl/calendar/calendar_arginfo.h index 5802d9f690e0a..47ea9200fe33a 100644 --- a/ext/intl/calendar/calendar_arginfo.h +++ b/ext/intl/calendar/calendar_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 7261d52837a7ac393453511d2c29ee9106407236 */ + * Stub hash: 8b8a98d5035880031ac42fda5e58bde54c1d85fc */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_IntlCalendar___construct, 0, 0, 0) ZEND_END_ARG_INFO() diff --git a/ext/intl/calendar/calendar_methods.cpp b/ext/intl/calendar/calendar_methods.cpp index 186c2597f427d..aaca633a4782a 100644 --- a/ext/intl/calendar/calendar_methods.cpp +++ b/ext/intl/calendar/calendar_methods.cpp @@ -43,6 +43,27 @@ extern "C" { using icu::Locale; +#define ZEND_VALUE_ERROR_INVALID_FIELD(argument, zpp_arg_position) \ + if (argument < 0 || argument >= UCAL_FIELD_COUNT) { \ + zend_argument_value_error(getThis() ? ((zpp_arg_position)-1) : zpp_arg_position, \ + "must be a valid field"); \ + RETURN_THROWS(); \ + } + +#define ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(argument, zpp_arg_position) \ + if (argument < INT32_MIN || argument > INT32_MAX) { \ + zend_argument_value_error(getThis() ? ((zpp_arg_position)-1) : zpp_arg_position, \ + "must be between %d and %d", INT32_MIN, INT32_MAX); \ + RETURN_THROWS(); \ + } + +#define ZEND_VALUE_ERROR_INVALID_DAY_OF_WEEK(argument, zpp_arg_position) \ + if (argument < UCAL_SUNDAY || argument > UCAL_SATURDAY) { \ + zend_argument_value_error(getThis() ? ((zpp_arg_position)-1) : zpp_arg_position, \ + "must be a valid day of the week"); \ + RETURN_THROWS(); \ + } + U_CFUNC PHP_METHOD(IntlCalendar, __construct) { zend_throw_exception( NULL, @@ -209,11 +230,9 @@ U_CFUNC PHP_FUNCTION(intlcal_get_available_locales) static void _php_intlcal_field_uec_ret_in32t_method( int32_t (Calendar::*func)(UCalendarDateFields, UErrorCode&) const, - const char *method_name, INTERNAL_FUNCTION_PARAMETERS) { zend_long field; - char *message; CALENDAR_METHOD_INIT_VARS; if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), @@ -221,12 +240,7 @@ static void _php_intlcal_field_uec_ret_in32t_method( RETURN_THROWS(); } - if (field < 0 || field >= UCAL_FIELD_COUNT) { - spprintf(&message, 0, "%s: invalid field", method_name); - intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, message, 1); - efree(message); - RETURN_FALSE; - } + ZEND_VALUE_ERROR_INVALID_FIELD(field, 2); CALENDAR_METHOD_FETCH_OBJECT; @@ -240,7 +254,7 @@ static void _php_intlcal_field_uec_ret_in32t_method( U_CFUNC PHP_FUNCTION(intlcal_get) { _php_intlcal_field_uec_ret_in32t_method(&Calendar::get, - "intlcal_get", INTERNAL_FUNCTION_PARAM_PASSTHRU); + INTERNAL_FUNCTION_PARAM_PASSTHRU); } U_CFUNC PHP_FUNCTION(intlcal_get_time) @@ -290,16 +304,8 @@ U_CFUNC PHP_FUNCTION(intlcal_add) RETURN_THROWS(); } - if (field < 0 || field >= UCAL_FIELD_COUNT) { - intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, - "intlcal_add: invalid field", 0); - RETURN_FALSE; - } - if (amount < INT32_MIN || amount > INT32_MAX) { - intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, - "intlcal_add: amount out of bounds", 0); - RETURN_FALSE; - } + ZEND_VALUE_ERROR_INVALID_FIELD(field, 2); + ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(amount, 3); CALENDAR_METHOD_FETCH_OBJECT; @@ -355,6 +361,7 @@ static void _php_intlcal_before_after( CALENDAR_METHOD_FETCH_OBJECT; when_co = Z_INTL_CALENDAR_P(when_object); + /* Can this ever happen ? */ if (when_co->ucal == NULL) { intl_errors_set(&co->err, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_before/after: Other IntlCalendar was unconstructed", 0); @@ -395,25 +402,19 @@ U_CFUNC PHP_FUNCTION(intlcal_set) } for (int i = 0; i < arg_num; i++) { - if (args[i] < INT32_MIN || args[i] > INT32_MAX) { - intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, - "intlcal_set: at least one of the arguments has an absolute value that is too large", 0); - RETURN_FALSE; - } + /* Arguments start at 1 */ + ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(args[i], i + 1); } CALENDAR_METHOD_FETCH_OBJECT; if (arg_num == 2) { - if (args[0] < 0 || args[0] >= UCAL_FIELD_COUNT) { - intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_set: invalid field", 0); - RETURN_FALSE; - } + ZEND_VALUE_ERROR_INVALID_FIELD(args[0], 2); co->ucal->set((UCalendarDateFields)args[0], (int32_t)args[1]); } else if (arg_num == 3) { co->ucal->set((int32_t)args[0], (int32_t)args[1], (int32_t)args[2]); } else if (arg_num == 4) { - zend_argument_count_error("No variant with 4 arguments"); + zend_argument_count_error("IntlCalendar::set() has no variant with exactly 4 parameters"); RETURN_THROWS(); } else if (arg_num == 5) { co->ucal->set((int32_t)args[0], (int32_t)args[1], (int32_t)args[2], (int32_t)args[3], (int32_t)args[4]); @@ -421,6 +422,7 @@ U_CFUNC PHP_FUNCTION(intlcal_set) co->ucal->set((int32_t)args[0], (int32_t)args[1], (int32_t)args[2], (int32_t)args[3], (int32_t)args[4], (int32_t)args[5]); } + // TODO Make void? RETURN_TRUE; } @@ -436,20 +438,13 @@ U_CFUNC PHP_FUNCTION(intlcal_roll) CALENDAR_METHOD_FETCH_OBJECT; - if (field < 0 || field >= UCAL_FIELD_COUNT) { - intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_roll: invalid field", 0); - RETURN_FALSE; - } + ZEND_VALUE_ERROR_INVALID_FIELD(field, 2); if (Z_TYPE_P(zvalue) == IS_FALSE || Z_TYPE_P(zvalue) == IS_TRUE) { value = Z_TYPE_P(zvalue) == IS_TRUE ? 1 : -1; } else { value = zval_get_long(zvalue); - - if (value < INT32_MIN || value > INT32_MAX) { - intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_roll: value out of bounds", 0); - RETURN_FALSE; - } + ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(value, 3); } co->ucal->roll((UCalendarDateFields)field, (int32_t)value, CALENDAR_ERROR_CODE(co)); @@ -475,11 +470,7 @@ U_CFUNC PHP_FUNCTION(intlcal_clear) if (field_is_null) { co->ucal->clear(); } else { - if (field < 0 || field >= UCAL_FIELD_COUNT) { - intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, - "intlcal_clear: invalid field", 0); - RETURN_FALSE; - } + ZEND_VALUE_ERROR_INVALID_FIELD(field, 2); co->ucal->clear((UCalendarDateFields)field); } @@ -498,11 +489,7 @@ U_CFUNC PHP_FUNCTION(intlcal_field_difference) RETURN_THROWS(); } - if (field < 0 || field >= UCAL_FIELD_COUNT) { - intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, - "intlcal_field_difference: invalid field", 0); - RETURN_FALSE; - } + ZEND_VALUE_ERROR_INVALID_FIELD(field, 3); CALENDAR_METHOD_FETCH_OBJECT; @@ -517,13 +504,13 @@ U_CFUNC PHP_FUNCTION(intlcal_field_difference) U_CFUNC PHP_FUNCTION(intlcal_get_actual_maximum) { _php_intlcal_field_uec_ret_in32t_method(&Calendar::getActualMaximum, - "intlcal_get_actual_maximum", INTERNAL_FUNCTION_PARAM_PASSTHRU); + INTERNAL_FUNCTION_PARAM_PASSTHRU); } U_CFUNC PHP_FUNCTION(intlcal_get_actual_minimum) { _php_intlcal_field_uec_ret_in32t_method(&Calendar::getActualMinimum, - "intlcal_get_actual_minimum", INTERNAL_FUNCTION_PARAM_PASSTHRU); + INTERNAL_FUNCTION_PARAM_PASSTHRU); } U_CFUNC PHP_FUNCTION(intlcal_get_day_of_week_type) @@ -536,11 +523,7 @@ U_CFUNC PHP_FUNCTION(intlcal_get_day_of_week_type) RETURN_THROWS(); } - if (dow < UCAL_SUNDAY || dow > UCAL_SATURDAY) { - intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, - "intlcal_get_day_of_week_type: invalid day of week", 0); - RETURN_FALSE; - } + ZEND_VALUE_ERROR_INVALID_DAY_OF_WEEK(dow, 2); CALENDAR_METHOD_FETCH_OBJECT; @@ -572,11 +555,9 @@ U_CFUNC PHP_FUNCTION(intlcal_get_first_day_of_week) static void _php_intlcal_field_ret_in32t_method( int32_t (Calendar::*func)(UCalendarDateFields) const, - const char *method_name, INTERNAL_FUNCTION_PARAMETERS) { zend_long field; - char *message; CALENDAR_METHOD_INIT_VARS; if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), @@ -584,12 +565,7 @@ static void _php_intlcal_field_ret_in32t_method( RETURN_THROWS(); } - if (field < 0 || field >= UCAL_FIELD_COUNT) { - spprintf(&message, 0, "%s: invalid field", method_name); - intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, message, 1); - efree(message); - RETURN_FALSE; - } + ZEND_VALUE_ERROR_INVALID_FIELD(field, 2); CALENDAR_METHOD_FETCH_OBJECT; @@ -602,13 +578,13 @@ static void _php_intlcal_field_ret_in32t_method( U_CFUNC PHP_FUNCTION(intlcal_get_greatest_minimum) { _php_intlcal_field_ret_in32t_method(&Calendar::getGreatestMinimum, - "intlcal_get_greatest_minimum", INTERNAL_FUNCTION_PARAM_PASSTHRU); + INTERNAL_FUNCTION_PARAM_PASSTHRU); } U_CFUNC PHP_FUNCTION(intlcal_get_least_maximum) { _php_intlcal_field_ret_in32t_method(&Calendar::getLeastMaximum, - "intlcal_get_least_maximum", INTERNAL_FUNCTION_PARAM_PASSTHRU); + INTERNAL_FUNCTION_PARAM_PASSTHRU); } U_CFUNC PHP_FUNCTION(intlcal_get_locale) @@ -622,9 +598,8 @@ U_CFUNC PHP_FUNCTION(intlcal_get_locale) } if (locale_type != ULOC_ACTUAL_LOCALE && locale_type != ULOC_VALID_LOCALE) { - intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, - "intlcal_get_locale: invalid locale type", 0); - RETURN_FALSE; + zend_argument_value_error(getThis() ? 1 : 2, "must be either Locale::ACTUAL_LOCALE or Locale::VALID_LOCALE"); + RETURN_THROWS(); } CALENDAR_METHOD_FETCH_OBJECT; @@ -640,7 +615,7 @@ U_CFUNC PHP_FUNCTION(intlcal_get_locale) U_CFUNC PHP_FUNCTION(intlcal_get_maximum) { _php_intlcal_field_ret_in32t_method(&Calendar::getMaximum, - "intlcal_get_maximum", INTERNAL_FUNCTION_PARAM_PASSTHRU); + INTERNAL_FUNCTION_PARAM_PASSTHRU); } U_CFUNC PHP_FUNCTION(intlcal_get_minimal_days_in_first_week) @@ -664,7 +639,7 @@ U_CFUNC PHP_FUNCTION(intlcal_get_minimal_days_in_first_week) U_CFUNC PHP_FUNCTION(intlcal_get_minimum) { _php_intlcal_field_ret_in32t_method(&Calendar::getMinimum, - "intlcal_get_minimum", INTERNAL_FUNCTION_PARAM_PASSTHRU); + INTERNAL_FUNCTION_PARAM_PASSTHRU); } U_CFUNC PHP_FUNCTION(intlcal_get_time_zone) @@ -712,11 +687,7 @@ U_CFUNC PHP_FUNCTION(intlcal_get_weekend_transition) RETURN_THROWS(); } - if (dow < UCAL_SUNDAY || dow > UCAL_SATURDAY) { - intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, - "intlcal_get_weekend_transition: invalid day of week", 0); - RETURN_FALSE; - } + ZEND_VALUE_ERROR_INVALID_DAY_OF_WEEK(dow, 2); CALENDAR_METHOD_FETCH_OBJECT; @@ -759,6 +730,7 @@ U_CFUNC PHP_FUNCTION(intlcal_is_equivalent_to) } other_co = Z_INTL_CALENDAR_P(other_object); + // Can this happen? if (other_co->ucal == NULL) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_is_equivalent_to:" " Other IntlCalendar is unconstructed", 0); @@ -794,11 +766,7 @@ U_CFUNC PHP_FUNCTION(intlcal_is_set) RETURN_THROWS(); } - if (field < 0 || field >= UCAL_FIELD_COUNT) { - intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, - "intlcal_is_set: invalid field", 0); - RETURN_FALSE; - } + ZEND_VALUE_ERROR_INVALID_FIELD(field, 2); CALENDAR_METHOD_FETCH_OBJECT; @@ -839,11 +807,7 @@ U_CFUNC PHP_FUNCTION(intlcal_set_first_day_of_week) RETURN_THROWS(); } - if (dow < UCAL_SUNDAY || dow > UCAL_SATURDAY) { - intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, - "intlcal_set_first_day_of_week: invalid day of week", 0); - RETURN_FALSE; - } + ZEND_VALUE_ERROR_INVALID_DAY_OF_WEEK(dow, 2); CALENDAR_METHOD_FETCH_OBJECT; @@ -879,11 +843,10 @@ U_CFUNC PHP_FUNCTION(intlcal_set_minimal_days_in_first_week) RETURN_THROWS(); } + // Use ZEND_VALUE_ERROR_INVALID_DAY_OF_WEEK ? if (num_days < 1 || num_days > 7) { - intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, - "intlcal_set_minimal_days_in_first_week: invalid number of days; " - "must be between 1 and 7", 0); - RETURN_FALSE; + zend_argument_value_error(getThis() ? 1 : 2, "must be between 1 and 7"); + RETURN_THROWS(); } CALENDAR_METHOD_FETCH_OBJECT; @@ -907,6 +870,7 @@ U_CFUNC PHP_FUNCTION(intlcal_equals) CALENDAR_METHOD_FETCH_OBJECT; other_co = Z_INTL_CALENDAR_P(other_object); + // Can this happen? if (other_co->ucal == NULL) { intl_errors_set(&co->err, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_equals: The second IntlCalendar is unconstructed", 0); @@ -958,15 +922,16 @@ U_CFUNC PHP_FUNCTION(intlcal_set_repeated_wall_time_option) } if (option != UCAL_WALLTIME_FIRST && option != UCAL_WALLTIME_LAST) { - intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, - "intlcal_set_repeated_wall_time_option: invalid option", 0); - RETURN_FALSE; + zend_argument_value_error(getThis() ? 1 : 2, "must be either IntlCalendar::WALLTIME_FIRST or " + "IntlCalendar::WALLTIME_LAST"); + RETURN_THROWS(); } CALENDAR_METHOD_FETCH_OBJECT; co->ucal->setRepeatedWallTimeOption((UCalendarWallTimeOption)option); + // TODO Return void? RETURN_TRUE; } @@ -982,15 +947,16 @@ U_CFUNC PHP_FUNCTION(intlcal_set_skipped_wall_time_option) if (option != UCAL_WALLTIME_FIRST && option != UCAL_WALLTIME_LAST && option != UCAL_WALLTIME_NEXT_VALID) { - intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, - "intlcal_set_skipped_wall_time_option: invalid option", 0); - RETURN_FALSE; + zend_argument_value_error(getThis() ? 1 : 2, "must be one of IntlCalendar::WALLTIME_FIRST, " + "IntlCalendar::WALLTIME_LAST, or IntlCalendar::WALLTIME_NEXT_VALID"); + RETURN_THROWS(); } CALENDAR_METHOD_FETCH_OBJECT; co->ucal->setSkippedWallTimeOption((UCalendarWallTimeOption)option); + // TODO Return void? RETURN_TRUE; } diff --git a/ext/intl/php_intl.stub.php b/ext/intl/php_intl.stub.php index 9708f6d35973b..90183d543451f 100644 --- a/ext/intl/php_intl.stub.php +++ b/ext/intl/php_intl.stub.php @@ -13,9 +13,9 @@ function intlcal_get_now(): float {} function intlcal_get_available_locales(): array {} -function intlcal_get(IntlCalendar $calendar, int $field): int|false {} +function intlcal_get(IntlCalendar $calendar, int $field): int {} -function intlcal_get_time(IntlCalendar $calendar): float|false {} +function intlcal_get_time(IntlCalendar $calendar): float {} function intlcal_set_time(IntlCalendar $calendar, float $date): bool {} @@ -35,35 +35,35 @@ function intlcal_roll(IntlCalendar $calendar, int $field, $amountOrUpOrDown): bo function intlcal_clear(IntlCalendar $calendar, ?int $field = null): bool {} -function intlcal_field_difference(IntlCalendar $calendar, float $when, int $field): int|false {} +function intlcal_field_difference(IntlCalendar $calendar, float $when, int $field): int {} -function intlcal_get_actual_maximum(IntlCalendar $calendar, int $field): int|false {} +function intlcal_get_actual_maximum(IntlCalendar $calendar, int $field): int {} -function intlcal_get_actual_minimum(IntlCalendar $calendar, int $field): int|false {} +function intlcal_get_actual_minimum(IntlCalendar $calendar, int $field): int {} -function intlcal_get_day_of_week_type(IntlCalendar $calendar, int $dayOfWeek): int|false {} +function intlcal_get_day_of_week_type(IntlCalendar $calendar, int $dayOfWeek): int {} -function intlcal_get_first_day_of_week(IntlCalendar $calendar): int|false {} +function intlcal_get_first_day_of_week(IntlCalendar $calendar): int {} -function intlcal_get_least_maximum(IntlCalendar $calendar, int $field): int|false {} +function intlcal_get_least_maximum(IntlCalendar $calendar, int $field): int {} -function intlcal_get_greatest_minimum(IntlCalendar $calendar, int $field): int|false {} +function intlcal_get_greatest_minimum(IntlCalendar $calendar, int $field): int {} -function intlcal_get_locale(IntlCalendar $calendar, int $localeType): string|false {} +function intlcal_get_locale(IntlCalendar $calendar, int $localeType): string {} -function intlcal_get_maximum(IntlCalendar $calendar, int $field): int|false {} +function intlcal_get_maximum(IntlCalendar $calendar, int $field): int {} -function intlcal_get_minimal_days_in_first_week(IntlCalendar $calendar): int|false {} +function intlcal_get_minimal_days_in_first_week(IntlCalendar $calendar): int {} function intlcal_set_minimal_days_in_first_week(IntlCalendar $calendar, int $numberOfDays): bool {} -function intlcal_get_minimum(IntlCalendar $calendar, int $field): int|false {} +function intlcal_get_minimum(IntlCalendar $calendar, int $field): int {} function intlcal_get_time_zone(IntlCalendar $calendar): IntlTimeZone|false {} function intlcal_get_type(IntlCalendar $calendar): string {} -function intlcal_get_weekend_transition(IntlCalendar $calendar, int $dayOfWeek): int|false {} +function intlcal_get_weekend_transition(IntlCalendar $calendar, int $dayOfWeek): int {} function intlcal_in_daylight_time(IntlCalendar $calendar): bool {} @@ -103,7 +103,7 @@ function intlgregcal_create_instance($timeZoneOrYear = UNKNOWN, $localeOrMonth = function intlgregcal_set_gregorian_change(IntlGregorianCalendar $calendar, float $change): bool {} -function intlgregcal_get_gregorian_change(IntlGregorianCalendar $calendar): float|false {} +function intlgregcal_get_gregorian_change(IntlGregorianCalendar $calendar): float {} function intlgregcal_is_leap_year(IntlGregorianCalendar $calendar, int $year): bool {} diff --git a/ext/intl/php_intl_arginfo.h b/ext/intl/php_intl_arginfo.h index f9e2cbd152009..be066553556bb 100644 --- a/ext/intl/php_intl_arginfo.h +++ b/ext/intl/php_intl_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 6130944985187815dd839f7425213f91c3261735 */ + * Stub hash: 2d42dc63fa243a1bc2eb79f46edf35d8f0bbbdb8 */ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_intlcal_create_instance, 0, 0, IntlCalendar, 1) ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, timeZone, "null") @@ -18,12 +18,12 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_intlcal_get_available_locales, 0, 0, IS_ARRAY, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_intlcal_get, 0, 2, MAY_BE_LONG|MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_intlcal_get, 0, 2, IS_LONG, 0) ZEND_ARG_OBJ_INFO(0, calendar, IntlCalendar, 0) ZEND_ARG_TYPE_INFO(0, field, IS_LONG, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_intlcal_get_time, 0, 1, MAY_BE_DOUBLE|MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_intlcal_get_time, 0, 1, IS_DOUBLE, 0) ZEND_ARG_OBJ_INFO(0, calendar, IntlCalendar, 0) ZEND_END_ARG_INFO() @@ -71,7 +71,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_intlcal_clear, 0, 1, _IS_BOOL, 0 ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, field, IS_LONG, 1, "null") ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_intlcal_field_difference, 0, 3, MAY_BE_LONG|MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_intlcal_field_difference, 0, 3, IS_LONG, 0) ZEND_ARG_OBJ_INFO(0, calendar, IntlCalendar, 0) ZEND_ARG_TYPE_INFO(0, when, IS_DOUBLE, 0) ZEND_ARG_TYPE_INFO(0, field, IS_LONG, 0) @@ -81,12 +81,12 @@ ZEND_END_ARG_INFO() #define arginfo_intlcal_get_actual_minimum arginfo_intlcal_get -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_intlcal_get_day_of_week_type, 0, 2, MAY_BE_LONG|MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_intlcal_get_day_of_week_type, 0, 2, IS_LONG, 0) ZEND_ARG_OBJ_INFO(0, calendar, IntlCalendar, 0) ZEND_ARG_TYPE_INFO(0, dayOfWeek, IS_LONG, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_intlcal_get_first_day_of_week, 0, 1, MAY_BE_LONG|MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_intlcal_get_first_day_of_week, 0, 1, IS_LONG, 0) ZEND_ARG_OBJ_INFO(0, calendar, IntlCalendar, 0) ZEND_END_ARG_INFO() @@ -94,7 +94,7 @@ ZEND_END_ARG_INFO() #define arginfo_intlcal_get_greatest_minimum arginfo_intlcal_get -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_intlcal_get_locale, 0, 2, MAY_BE_STRING|MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_intlcal_get_locale, 0, 2, IS_STRING, 0) ZEND_ARG_OBJ_INFO(0, calendar, IntlCalendar, 0) ZEND_ARG_TYPE_INFO(0, localeType, IS_LONG, 0) ZEND_END_ARG_INFO() @@ -148,13 +148,11 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_intlcal_set_lenient, 0, 2, _IS_B ZEND_ARG_TYPE_INFO(0, isLenient, _IS_BOOL, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_intlcal_get_repeated_wall_time_option, 0, 1, IS_LONG, 0) - ZEND_ARG_OBJ_INFO(0, calendar, IntlCalendar, 0) -ZEND_END_ARG_INFO() +#define arginfo_intlcal_get_repeated_wall_time_option arginfo_intlcal_get_first_day_of_week #define arginfo_intlcal_equals arginfo_intlcal_after -#define arginfo_intlcal_get_skipped_wall_time_option arginfo_intlcal_get_repeated_wall_time_option +#define arginfo_intlcal_get_skipped_wall_time_option arginfo_intlcal_get_first_day_of_week ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_intlcal_set_repeated_wall_time_option, 0, 2, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, calendar, IntlCalendar, 0) @@ -172,7 +170,9 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_intlcal_to_date_time, 0, 1, ZEND_ARG_OBJ_INFO(0, calendar, IntlCalendar, 0) ZEND_END_ARG_INFO() -#define arginfo_intlcal_get_error_code arginfo_intlcal_get_first_day_of_week +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_intlcal_get_error_code, 0, 1, MAY_BE_LONG|MAY_BE_FALSE) + ZEND_ARG_OBJ_INFO(0, calendar, IntlCalendar, 0) +ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_intlcal_get_error_message, 0, 1, MAY_BE_STRING|MAY_BE_FALSE) ZEND_ARG_OBJ_INFO(0, calendar, IntlCalendar, 0) @@ -192,7 +192,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_intlgregcal_set_gregorian_change ZEND_ARG_TYPE_INFO(0, change, IS_DOUBLE, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_intlgregcal_get_gregorian_change, 0, 1, MAY_BE_DOUBLE|MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_intlgregcal_get_gregorian_change, 0, 1, IS_DOUBLE, 0) ZEND_ARG_OBJ_INFO(0, calendar, IntlGregorianCalendar, 0) ZEND_END_ARG_INFO() diff --git a/ext/intl/tests/calendar_clear_error.phpt b/ext/intl/tests/calendar_clear_error.phpt index dd2c1e0e75b6f..12e5098ec5a4d 100644 --- a/ext/intl/tests/calendar_clear_error.phpt +++ b/ext/intl/tests/calendar_clear_error.phpt @@ -8,23 +8,26 @@ if (!extension_loaded('intl')) die('skip intl extension not enabled'); --FILE-- clear(-1)); +try { + var_dump($c->clear(-1)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(intlcal_clear($c, -1)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} -var_dump(intlcal_clear($c, -1)); -var_dump(intlcal_clear(1, 2)); ---EXPECTF-- -Warning: IntlCalendar::clear(): intlcal_clear: invalid field in %s on line %d -bool(false) - -Warning: intlcal_clear(): intlcal_clear: invalid field in %s on line %d -bool(false) - -Fatal error: Uncaught TypeError: intlcal_clear(): Argument #1 ($calendar) must be of type IntlCalendar, int given in %s:%d -Stack trace: -#0 %s(%d): intlcal_clear(1, 2) -#1 {main} - thrown in %s on line %d +try { + var_dump(intlcal_clear(1, 2)); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} +--EXPECT-- +IntlCalendar::clear(): Argument #1 ($field) must be a valid field +intlcal_clear(): Argument #2 ($field) must be a valid field +intlcal_clear(): Argument #1 ($calendar) must be of type IntlCalendar, int given diff --git a/ext/intl/tests/calendar_getDayOfWeekType_error.phpt b/ext/intl/tests/calendar_getDayOfWeekType_error.phpt index 5408f966e2d6e..9fee8999012e2 100644 --- a/ext/intl/tests/calendar_getDayOfWeekType_error.phpt +++ b/ext/intl/tests/calendar_getDayOfWeekType_error.phpt @@ -8,19 +8,20 @@ if (!extension_loaded('intl')) die('skip intl extension not enabled'); --FILE-- getDayOfWeekType(0)); +try { + var_dump($c->getDayOfWeekType(0)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} -var_dump(intlcal_get_day_of_week_type(1, 1)); ---EXPECTF-- -Warning: IntlCalendar::getDayOfWeekType(): intlcal_get_day_of_week_type: invalid day of week in %s on line %d -bool(false) +try { + var_dump(intlcal_get_day_of_week_type(1, 1)); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} -Fatal error: Uncaught TypeError: intlcal_get_day_of_week_type(): Argument #1 ($calendar) must be of type IntlCalendar, int given in %s:%d -Stack trace: -#0 %s(%d): intlcal_get_day_of_week_type(1, 1) -#1 {main} - thrown in %s on line %d +--EXPECT-- +IntlCalendar::getDayOfWeekType(): Argument #1 ($dayOfWeek) must be a valid day of the week +intlcal_get_day_of_week_type(): Argument #1 ($calendar) must be of type IntlCalendar, int given diff --git a/ext/intl/tests/calendar_getWeekendTransition_error.phpt b/ext/intl/tests/calendar_getWeekendTransition_error.phpt index 3be22cfc9c872..63a1e7d07bf53 100644 --- a/ext/intl/tests/calendar_getWeekendTransition_error.phpt +++ b/ext/intl/tests/calendar_getWeekendTransition_error.phpt @@ -11,15 +11,19 @@ if (!extension_loaded('intl')) ini_set("intl.error_level", E_WARNING); $c = new IntlGregorianCalendar(NULL, 'pt_PT'); -var_dump($c->getWeekendTransition(0)); -var_dump(intlcal_get_weekend_transition(1, 1)); ---EXPECTF-- -Warning: IntlCalendar::getWeekendTransition(): intlcal_get_weekend_transition: invalid day of week in %s on line %d -bool(false) +try { + var_dump($c->getWeekendTransition(0)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} -Fatal error: Uncaught TypeError: intlcal_get_weekend_transition(): Argument #1 ($calendar) must be of type IntlCalendar, int given in %s:%d -Stack trace: -#0 %s(%d): intlcal_get_weekend_transition(1, 1) -#1 {main} - thrown in %s on line %d +try { + var_dump(intlcal_get_weekend_transition(1, 1)); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} + +--EXPECT-- +IntlCalendar::getWeekendTransition(): Argument #1 ($dayOfWeek) must be a valid day of the week +intlcal_get_weekend_transition(): Argument #1 ($calendar) must be of type IntlCalendar, int given diff --git a/ext/intl/tests/calendar_get_Least_Greatest_Minimum_Maximum_error.phpt b/ext/intl/tests/calendar_get_Least_Greatest_Minimum_Maximum_error.phpt index 318738f0941f5..0199573178dd4 100644 --- a/ext/intl/tests/calendar_get_Least_Greatest_Minimum_Maximum_error.phpt +++ b/ext/intl/tests/calendar_get_Least_Greatest_Minimum_Maximum_error.phpt @@ -8,73 +8,81 @@ if (!extension_loaded('intl')) die('skip intl extension not enabled'); --FILE-- getLeastMaximum(-1)); -var_dump($c->getMaximum(-1)); -var_dump($c->getGreatestMinimum(-1)); -var_dump($c->getMinimum(-1)); - -var_dump(intlcal_get_least_maximum($c, -1)); -var_dump(intlcal_get_maximum($c, -1)); -var_dump(intlcal_get_greatest_minimum($c, -1)); -var_dump(intlcal_get_minimum($c, -1)); +try { + var_dump($c->getLeastMaximum(-1)); +} catch (Error $e) { + echo get_class($e) . ': ' . $e->getCode() . ', ' . $e->getMessage() . \PHP_EOL; +} +try { + var_dump($c->getMaximum(-1)); +} catch (Error $e) { + echo get_class($e) . ': ' . $e->getCode() . ', ' . $e->getMessage() . \PHP_EOL; +} +try { + var_dump($c->getGreatestMinimum(-1)); +} catch (Error $e) { + echo get_class($e) . ': ' . $e->getCode() . ', ' . $e->getMessage() . \PHP_EOL; +} +try { + var_dump($c->getMinimum(-1)); +} catch (Error $e) { + echo get_class($e) . ': ' . $e->getCode() . ', ' . $e->getMessage() . \PHP_EOL; +} -function eh($errno, $errstr) { -echo "error: $errno, $errstr\n"; +try { + var_dump(intlcal_get_least_maximum($c, -1)); +} catch (Error $e) { + echo get_class($e) . ': ' . $e->getCode() . ', ' . $e->getMessage() . \PHP_EOL; +} +try { + var_dump(intlcal_get_maximum($c, -1)); +} catch (Error $e) { + echo get_class($e) . ': ' . $e->getCode() . ', ' . $e->getMessage() . \PHP_EOL; +} +try { + var_dump(intlcal_get_greatest_minimum($c, -1)); +} catch (Error $e) { + echo get_class($e) . ': ' . $e->getCode() . ', ' . $e->getMessage() . \PHP_EOL; +} +try { + var_dump(intlcal_get_minimum($c, -1)); +} catch (Error $e) { + echo get_class($e) . ': ' . $e->getCode() . ', ' . $e->getMessage() . \PHP_EOL; } -set_error_handler('eh'); try { var_dump(intlcal_get_least_maximum(1, 1)); -} catch (Error $ex) { - echo "error: " . $ex->getCode() . ", " . $ex->getMessage() . "\n\n"; +} catch (Error $e) { + echo get_class($e) . ': ' . $e->getCode() . ', ' . $e->getMessage() . \PHP_EOL; } try { var_dump(intlcal_get_maximum(1, 1)); -} catch (Error $ex) { - echo "error: " . $ex->getCode() . ", " . $ex->getMessage() . "\n\n"; +} catch (Error $e) { + echo get_class($e) . ': ' . $e->getCode() . ', ' . $e->getMessage() . \PHP_EOL; } try { var_dump(intlcal_get_greatest_minimum(1, -1)); -} catch (Error $ex) { - echo "error: " . $ex->getCode() . ", " . $ex->getMessage() . "\n\n"; +} catch (Error $e) { + echo get_class($e) . ': ' . $e->getCode() . ', ' . $e->getMessage() . \PHP_EOL; } try { var_dump(intlcal_get_minimum(1, -1)); -} catch (Error $ex) { - echo "error: " . $ex->getCode() . ", " . $ex->getMessage() . "\n\n"; +} catch (Error $e) { + echo get_class($e) . ': ' . $e->getCode() . ', ' . $e->getMessage() . \PHP_EOL; } ---EXPECTF-- -Warning: IntlCalendar::getLeastMaximum(): intlcal_get_least_maximum: invalid field in %s on line %d -bool(false) - -Warning: IntlCalendar::getMaximum(): intlcal_get_maximum: invalid field in %s on line %d -bool(false) - -Warning: IntlCalendar::getGreatestMinimum(): intlcal_get_greatest_minimum: invalid field in %s on line %d -bool(false) - -Warning: IntlCalendar::getMinimum(): intlcal_get_minimum: invalid field in %s on line %d -bool(false) - -Warning: intlcal_get_least_maximum(): intlcal_get_least_maximum: invalid field in %s on line %d -bool(false) - -Warning: intlcal_get_maximum(): intlcal_get_maximum: invalid field in %s on line %d -bool(false) - -Warning: intlcal_get_greatest_minimum(): intlcal_get_greatest_minimum: invalid field in %s on line %d -bool(false) - -Warning: intlcal_get_minimum(): intlcal_get_minimum: invalid field in %s on line %d -bool(false) -error: 0, intlcal_get_least_maximum(): Argument #1 ($calendar) must be of type IntlCalendar, int given - -error: 0, intlcal_get_maximum(): Argument #1 ($calendar) must be of type IntlCalendar, int given - -error: 0, intlcal_get_greatest_minimum(): Argument #1 ($calendar) must be of type IntlCalendar, int given - -error: 0, intlcal_get_minimum(): Argument #1 ($calendar) must be of type IntlCalendar, int given +--EXPECT-- +ValueError: 0, IntlCalendar::getLeastMaximum(): Argument #1 ($field) must be a valid field +ValueError: 0, IntlCalendar::getMaximum(): Argument #1 ($field) must be a valid field +ValueError: 0, IntlCalendar::getGreatestMinimum(): Argument #1 ($field) must be a valid field +ValueError: 0, IntlCalendar::getMinimum(): Argument #1 ($field) must be a valid field +ValueError: 0, intlcal_get_least_maximum(): Argument #2 ($field) must be a valid field +ValueError: 0, intlcal_get_maximum(): Argument #2 ($field) must be a valid field +ValueError: 0, intlcal_get_greatest_minimum(): Argument #2 ($field) must be a valid field +ValueError: 0, intlcal_get_minimum(): Argument #2 ($field) must be a valid field +TypeError: 0, intlcal_get_least_maximum(): Argument #1 ($calendar) must be of type IntlCalendar, int given +TypeError: 0, intlcal_get_maximum(): Argument #1 ($calendar) must be of type IntlCalendar, int given +TypeError: 0, intlcal_get_greatest_minimum(): Argument #1 ($calendar) must be of type IntlCalendar, int given +TypeError: 0, intlcal_get_minimum(): Argument #1 ($calendar) must be of type IntlCalendar, int given diff --git a/ext/intl/tests/calendar_get_getActualMaximum_Minumum_error.phpt b/ext/intl/tests/calendar_get_getActualMaximum_Minumum_error.phpt index 3853d612a3358..2b5f344cb14e2 100644 --- a/ext/intl/tests/calendar_get_getActualMaximum_Minumum_error.phpt +++ b/ext/intl/tests/calendar_get_getActualMaximum_Minumum_error.phpt @@ -8,21 +8,27 @@ if (!extension_loaded('intl')) die('skip intl extension not enabled'); --FILE-- get(-1)); -var_dump($c->getActualMaximum(-1)); -var_dump($c->getActualMinimum(-1)); +try { + var_dump($c->get(-1)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump($c->getActualMaximum(-1)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump($c->getActualMinimum(-1)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} ?> ---EXPECTF-- -Warning: IntlCalendar::get(): intlcal_get: invalid field in %s on line %d -bool(false) - -Warning: IntlCalendar::getActualMaximum(): intlcal_get_actual_maximum: invalid field in %s on line %d -bool(false) - -Warning: IntlCalendar::getActualMinimum(): intlcal_get_actual_minimum: invalid field in %s on line %d -bool(false) +--EXPECT-- +IntlCalendar::get(): Argument #1 ($field) must be a valid field +IntlCalendar::getActualMaximum(): Argument #1 ($field) must be a valid field +IntlCalendar::getActualMinimum(): Argument #1 ($field) must be a valid field diff --git a/ext/intl/tests/calendar_get_getActualMaximum_Minumum_error2.phpt b/ext/intl/tests/calendar_get_getActualMaximum_Minumum_error2.phpt index 207d9e5cdb795..95ecf0e08fd92 100644 --- a/ext/intl/tests/calendar_get_getActualMaximum_Minumum_error2.phpt +++ b/ext/intl/tests/calendar_get_getActualMaximum_Minumum_error2.phpt @@ -8,99 +8,82 @@ if (!extension_loaded('intl')) die('skip intl extension not enabled'); --FILE-- getCode() . ", " . $ex->getMessage() . "\n\n"; +} catch (Error $e) { + echo get_class($e) . ': ' . $e->getCode() . ', ' . $e->getMessage() . \PHP_EOL; } try { var_dump(intlcal_get_actual_maximum($c)); -} catch (Error $ex) { - echo "error: " . $ex->getCode() . ", " . $ex->getMessage() . "\n\n"; +} catch (Error $e) { + echo get_class($e) . ': ' . $e->getCode() . ', ' . $e->getMessage() . \PHP_EOL; } try { var_dump(intlcal_get_actual_minimum($c)); -} catch (Error $ex) { - echo "error: " . $ex->getCode() . ", " . $ex->getMessage() . "\n\n"; +} catch (Error $e) { + echo get_class($e) . ': ' . $e->getCode() . ', ' . $e->getMessage() . \PHP_EOL; } try { var_dump(intlcal_get($c, -1)); -} catch (Error $ex) { - echo "error: " . $ex->getCode() . ", " . $ex->getMessage() . "\n\n"; +} catch (Error $e) { + echo get_class($e) . ': ' . $e->getCode() . ', ' . $e->getMessage() . \PHP_EOL; } try { var_dump(intlcal_get_actual_maximum($c, -1)); -} catch (Error $ex) { - echo "error: " . $ex->getCode() . ", " . $ex->getMessage() . "\n\n"; +} catch (Error $e) { + echo get_class($e) . ': ' . $e->getCode() . ', ' . $e->getMessage() . \PHP_EOL; } try { var_dump(intlcal_get_actual_minimum($c, -1)); -} catch (Error $ex) { - echo "error: " . $ex->getCode() . ", " . $ex->getMessage() . "\n\n"; +} catch (Error $e) { + echo get_class($e) . ': ' . $e->getCode() . ', ' . $e->getMessage() . \PHP_EOL; } try { var_dump(intlcal_get($c, "s")); -} catch (Error $ex) { - echo "error: " . $ex->getCode() . ", " . $ex->getMessage() . "\n\n"; +} catch (Error $e) { + echo get_class($e) . ': ' . $e->getCode() . ', ' . $e->getMessage() . \PHP_EOL; } try { var_dump(intlcal_get_actual_maximum($c, "s")); -} catch (Error $ex) { - echo "error: " . $ex->getCode() . ", " . $ex->getMessage() . "\n\n"; +} catch (Error $e) { + echo get_class($e) . ': ' . $e->getCode() . ', ' . $e->getMessage() . \PHP_EOL; } try { var_dump(intlcal_get_actual_minimum($c, "s")); -} catch (Error $ex) { - echo "error: " . $ex->getCode() . ", " . $ex->getMessage() . "\n\n"; +} catch (Error $e) { + echo get_class($e) . ': ' . $e->getCode() . ', ' . $e->getMessage() . \PHP_EOL; } try { var_dump(intlcal_get(1)); -} catch (Error $ex) { - echo "error: " . $ex->getCode() . ", " . $ex->getMessage() . "\n\n"; +} catch (Error $e) { + echo get_class($e) . ': ' . $e->getCode() . ', ' . $e->getMessage() . \PHP_EOL; } try { var_dump(intlcal_get_actual_maximum(1)); -} catch (Error $ex) { - echo "error: " . $ex->getCode() . ", " . $ex->getMessage() . "\n\n"; +} catch (Error $e) { + echo get_class($e) . ': ' . $e->getCode() . ', ' . $e->getMessage() . \PHP_EOL; } try { var_dump(intlcal_get_actual_minimum(1)); -} catch (Error $ex) { - echo "error: " . $ex->getCode() . ", " . $ex->getMessage() . "\n\n"; +} catch (Error $e) { + echo get_class($e) . ': ' . $e->getCode() . ', ' . $e->getMessage() . \PHP_EOL; } --EXPECT-- -error: 0, intlcal_get() expects exactly 2 parameters, 1 given - -error: 0, intlcal_get_actual_maximum() expects exactly 2 parameters, 1 given - -error: 0, intlcal_get_actual_minimum() expects exactly 2 parameters, 1 given - -error: 2, intlcal_get(): intlcal_get: invalid field -bool(false) -error: 2, intlcal_get_actual_maximum(): intlcal_get_actual_maximum: invalid field -bool(false) -error: 2, intlcal_get_actual_minimum(): intlcal_get_actual_minimum: invalid field -bool(false) -error: 0, intlcal_get(): Argument #2 ($field) must be of type int, string given - -error: 0, intlcal_get_actual_maximum(): Argument #2 ($field) must be of type int, string given - -error: 0, intlcal_get_actual_minimum(): Argument #2 ($field) must be of type int, string given - -error: 0, intlcal_get() expects exactly 2 parameters, 1 given - -error: 0, intlcal_get_actual_maximum() expects exactly 2 parameters, 1 given - -error: 0, intlcal_get_actual_minimum() expects exactly 2 parameters, 1 given +ArgumentCountError: 0, intlcal_get() expects exactly 2 parameters, 1 given +ArgumentCountError: 0, intlcal_get_actual_maximum() expects exactly 2 parameters, 1 given +ArgumentCountError: 0, intlcal_get_actual_minimum() expects exactly 2 parameters, 1 given +ValueError: 0, intlcal_get(): Argument #2 ($field) must be a valid field +ValueError: 0, intlcal_get_actual_maximum(): Argument #2 ($field) must be a valid field +ValueError: 0, intlcal_get_actual_minimum(): Argument #2 ($field) must be a valid field +TypeError: 0, intlcal_get(): Argument #2 ($field) must be of type int, string given +TypeError: 0, intlcal_get_actual_maximum(): Argument #2 ($field) must be of type int, string given +TypeError: 0, intlcal_get_actual_minimum(): Argument #2 ($field) must be of type int, string given +ArgumentCountError: 0, intlcal_get() expects exactly 2 parameters, 1 given +ArgumentCountError: 0, intlcal_get_actual_maximum() expects exactly 2 parameters, 1 given +ArgumentCountError: 0, intlcal_get_actual_minimum() expects exactly 2 parameters, 1 given diff --git a/ext/intl/tests/calendar_isSet_error.phpt b/ext/intl/tests/calendar_isSet_error.phpt index 969a5130a599d..ccd25f621a9c8 100644 --- a/ext/intl/tests/calendar_isSet_error.phpt +++ b/ext/intl/tests/calendar_isSet_error.phpt @@ -8,19 +8,21 @@ if (!extension_loaded('intl')) die('skip intl extension not enabled'); --FILE-- isSet(-1)); +try { + var_dump($c->isSet(-1)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} -var_dump(intlcal_is_set(1, 2)); ---EXPECTF-- -Warning: IntlCalendar::isSet(): intlcal_is_set: invalid field in %s on line %d -bool(false) +try { + var_dump(intlcal_is_set(1, 2)); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} -Fatal error: Uncaught TypeError: intlcal_is_set(): Argument #1 ($calendar) must be of type IntlCalendar, int given in %s:%d -Stack trace: -#0 %s(%d): intlcal_is_set(1, 2) -#1 {main} - thrown in %s on line %d +--EXPECT-- +IntlCalendar::isSet(): Argument #1 ($field) must be a valid field +intlcal_is_set(): Argument #1 ($calendar) must be of type IntlCalendar, int given diff --git a/ext/intl/tests/calendar_roll_error.phpt b/ext/intl/tests/calendar_roll_error.phpt index de110a864cb05..77ce6e16a8c18 100644 --- a/ext/intl/tests/calendar_roll_error.phpt +++ b/ext/intl/tests/calendar_roll_error.phpt @@ -8,19 +8,20 @@ if (!extension_loaded('intl')) die('skip intl extension not enabled'); --FILE-- roll(-1, 2)); +try { + var_dump($c->roll(-1, 2)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} -var_dump(intlcal_roll(1, 2, 3)); +try { + var_dump(intlcal_roll(1, 2, 3)); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} --EXPECTF-- -Warning: IntlCalendar::roll(): intlcal_roll: invalid field in %s on line %d -bool(false) - -Fatal error: Uncaught TypeError: intlcal_roll(): Argument #1 ($calendar) must be of type IntlCalendar, int given in %s:%d -Stack trace: -#0 %s(%d): intlcal_roll(1, 2, 3) -#1 {main} - thrown in %s on line %d +IntlCalendar::roll(): Argument #1 ($field) must be a valid field +intlcal_roll(): Argument #1 ($calendar) must be of type IntlCalendar, int given diff --git a/ext/intl/tests/calendar_setFirstDayOfWeek_error.phpt b/ext/intl/tests/calendar_setFirstDayOfWeek_error.phpt index 163e41fe48286..e3e3797b7a125 100644 --- a/ext/intl/tests/calendar_setFirstDayOfWeek_error.phpt +++ b/ext/intl/tests/calendar_setFirstDayOfWeek_error.phpt @@ -8,23 +8,27 @@ if (!extension_loaded('intl')) die('skip intl extension not enabled'); --FILE-- setFirstDayOfWeek(0)); +try { + var_dump($c->setFirstDayOfWeek(0)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} -var_dump(intlcal_set_first_day_of_week($c, 0)); -var_dump(intlcal_set_first_day_of_week(1, 2)); ---EXPECTF-- -Warning: IntlCalendar::setFirstDayOfWeek(): intlcal_set_first_day_of_week: invalid day of week in %s on line %d -bool(false) +try { + var_dump(intlcal_set_first_day_of_week($c, 0)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(intlcal_set_first_day_of_week(1, 2)); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} -Warning: intlcal_set_first_day_of_week(): intlcal_set_first_day_of_week: invalid day of week in %s on line %d -bool(false) - -Fatal error: Uncaught TypeError: intlcal_set_first_day_of_week(): Argument #1 ($calendar) must be of type IntlCalendar, int given in %s:%d -Stack trace: -#0 %s(%d): intlcal_set_first_day_of_week(1, 2) -#1 {main} - thrown in %s on line %d +--EXPECT-- +IntlCalendar::setFirstDayOfWeek(): Argument #1 ($dayOfWeek) must be a valid day of the week +intlcal_set_first_day_of_week(): Argument #2 ($dayOfWeek) must be a valid day of the week +intlcal_set_first_day_of_week(): Argument #1 ($calendar) must be of type IntlCalendar, int given diff --git a/ext/intl/tests/calendar_setMinimalDaysInFirstWeek_error.phpt b/ext/intl/tests/calendar_setMinimalDaysInFirstWeek_error.phpt index c1b1a944fb87f..04c4811eb0a30 100644 --- a/ext/intl/tests/calendar_setMinimalDaysInFirstWeek_error.phpt +++ b/ext/intl/tests/calendar_setMinimalDaysInFirstWeek_error.phpt @@ -8,23 +8,27 @@ if (!extension_loaded('intl')) die('skip intl extension not enabled'); --FILE-- setMinimalDaysInFirstWeek(0)); +try { + var_dump($c->setMinimalDaysInFirstWeek(0)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} -var_dump(intlcal_set_minimal_days_in_first_week($c, 0)); -var_dump(intlcal_set_minimal_days_in_first_week(1, 2)); ---EXPECTF-- -Warning: IntlCalendar::setMinimalDaysInFirstWeek(): intlcal_set_minimal_days_in_first_week: invalid number of days; must be between 1 and 7 in %s on line %d -bool(false) +try { + var_dump(intlcal_set_minimal_days_in_first_week($c, 0)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(intlcal_set_minimal_days_in_first_week(1, 2)); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} -Warning: intlcal_set_minimal_days_in_first_week(): intlcal_set_minimal_days_in_first_week: invalid number of days; must be between 1 and 7 in %s on line %d -bool(false) - -Fatal error: Uncaught TypeError: intlcal_set_minimal_days_in_first_week(): Argument #1 ($calendar) must be of type IntlCalendar, int given in %s:%d -Stack trace: -#0 %s(%d): intlcal_set_minimal_days_in_first_week(1, 2) -#1 {main} - thrown in %s on line %d +--EXPECT-- +IntlCalendar::setMinimalDaysInFirstWeek(): Argument #1 ($numberOfDays) must be between 1 and 7 +intlcal_set_minimal_days_in_first_week(): Argument #2 ($numberOfDays) must be between 1 and 7 +intlcal_set_minimal_days_in_first_week(): Argument #1 ($calendar) must be of type IntlCalendar, int given diff --git a/ext/intl/tests/calendar_setSkipped_RepeatedWallTimeOption_error.phpt b/ext/intl/tests/calendar_setSkipped_RepeatedWallTimeOption_error.phpt index c89e502e7a7a3..80ed808e47db1 100644 --- a/ext/intl/tests/calendar_setSkipped_RepeatedWallTimeOption_error.phpt +++ b/ext/intl/tests/calendar_setSkipped_RepeatedWallTimeOption_error.phpt @@ -12,19 +12,23 @@ ini_set("intl.error_level", E_WARNING); $c = new IntlGregorianCalendar(NULL, 'pt_PT'); -var_dump($c->setSkippedWallTimeOption(3)); -var_dump($c->setRepeatedWallTimeOption(2)); +try { + var_dump($c->setSkippedWallTimeOption(3)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump($c->setRepeatedWallTimeOption(2)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} -var_dump(intlcal_set_repeated_wall_time_option(1, 1)); ---EXPECTF-- -Warning: IntlCalendar::setSkippedWallTimeOption(): intlcal_set_skipped_wall_time_option: invalid option in %s on line %d -bool(false) - -Warning: IntlCalendar::setRepeatedWallTimeOption(): intlcal_set_repeated_wall_time_option: invalid option in %s on line %d -bool(false) - -Fatal error: Uncaught TypeError: intlcal_set_repeated_wall_time_option(): Argument #1 ($calendar) must be of type IntlCalendar, int given in %s:%d -Stack trace: -#0 %s(%d): intlcal_set_repeated_wall_time_option(1, 1) -#1 {main} - thrown in %s on line %d +try { + var_dump(intlcal_set_repeated_wall_time_option(1, 1)); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} +--EXPECT-- +IntlCalendar::setSkippedWallTimeOption(): Argument #1 ($wallTimeOption) must be one of IntlCalendar::WALLTIME_FIRST, IntlCalendar::WALLTIME_LAST, or IntlCalendar::WALLTIME_NEXT_VALID +IntlCalendar::setRepeatedWallTimeOption(): Argument #1 ($wallTimeOption) must be either IntlCalendar::WALLTIME_FIRST or IntlCalendar::WALLTIME_LAST +intlcal_set_repeated_wall_time_option(): Argument #1 ($calendar) must be of type IntlCalendar, int given diff --git a/ext/intl/tests/calendar_set_error.phpt b/ext/intl/tests/calendar_set_error.phpt index 21133536049ce..236d3b6451dbb 100644 --- a/ext/intl/tests/calendar_set_error.phpt +++ b/ext/intl/tests/calendar_set_error.phpt @@ -24,22 +24,26 @@ try { echo $exception->getMessage() . "\n"; } -var_dump($c->set(-1, 2)); - -var_dump(intlcal_set($c, -1, 2)); -var_dump(intlcal_set(1, 2, 3)); ---EXPECTF-- -IntlCalendar::set() expects at most 6 parameters, 7 given -No variant with 4 arguments - -Warning: IntlCalendar::set(): intlcal_set: invalid field in %s on line %d -bool(false) +try { + var_dump($c->set(-1, 2)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} -Warning: intlcal_set(): intlcal_set: invalid field in %s on line %d -bool(false) +try { + var_dump(intlcal_set($c, -1, 2)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} -Fatal error: Uncaught TypeError: intlcal_set(): Argument #1 ($calendar) must be of type IntlCalendar, int given in %s:%d -Stack trace: -#0 %s(%d): intlcal_set(1, 2, 3) -#1 {main} - thrown in %s on line %d +try { + var_dump(intlcal_set(1, 2, 3)); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} +--EXPECT-- +IntlCalendar::set() expects at most 6 parameters, 7 given +IntlCalendar::set() has no variant with exactly 4 parameters +IntlCalendar::set(): Argument #1 ($year) must be a valid field +intlcal_set(): Argument #2 ($year) must be a valid field +intlcal_set(): Argument #1 ($calendar) must be of type IntlCalendar, int given From 7d2e249588c2400309629cce1ada554637113ee4 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Fri, 5 Jun 2020 20:03:10 +0200 Subject: [PATCH 3/8] Promote IntlGregorianCalendar warnings to Error Seems no test are covering these cases --- ext/intl/calendar/gregoriancalendar_methods.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/ext/intl/calendar/gregoriancalendar_methods.cpp b/ext/intl/calendar/gregoriancalendar_methods.cpp index 3a4d75965a0e2..3b7bbd165474f 100644 --- a/ext/intl/calendar/gregoriancalendar_methods.cpp +++ b/ext/intl/calendar/gregoriancalendar_methods.cpp @@ -107,6 +107,7 @@ static void _php_intlgregcal_constructor_body( gcal = new GregorianCalendar(tz, Locale::createFromName(locale), status); + // Should this throw? if (U_FAILURE(status)) { intl_error_set(NULL, status, "intlgregcal_create_instance: error " "creating ICU GregorianCalendar from time zone and locale", 0); @@ -124,14 +125,9 @@ static void _php_intlgregcal_constructor_body( // From date/time (3, 5 or 6 arguments) for (int i = 0; i < variant; i++) { if (largs[i] < INT32_MIN || largs[i] > INT32_MAX) { - intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, - "intlgregcal_create_instance: at least one of the arguments" - " has an absolute value that is too large", 0); - if (!is_constructor) { - zval_ptr_dtor(return_value); - RETVAL_NULL(); - } - return; + zend_argument_value_error(getThis() ? (i-1):i, + "must be between %d and %d", INT32_MIN, INT32_MAX); + RETURN_THROWS(); } } @@ -244,9 +240,8 @@ U_CFUNC PHP_FUNCTION(intlgregcal_is_leap_year) } if (year < INT32_MIN || year > INT32_MAX) { - intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, - "intlgregcal_is_leap_year: year out of bounds", 0); - RETURN_FALSE; + zend_argument_value_error(getThis() ? 1:2, "must be between %d and %d", INT32_MIN, INT32_MAX); + RETURN_THROWS(); } CALENDAR_METHOD_FETCH_OBJECT; From 4f6683443e0209925e3965b85a6bbb509b3e26c4 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Fri, 5 Jun 2020 20:16:41 +0200 Subject: [PATCH 4/8] Add some todo comments --- ext/intl/calendar/calendar_methods.cpp | 1 + ext/intl/collator/collator_convert.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/ext/intl/calendar/calendar_methods.cpp b/ext/intl/calendar/calendar_methods.cpp index aaca633a4782a..822f11601e70d 100644 --- a/ext/intl/calendar/calendar_methods.cpp +++ b/ext/intl/calendar/calendar_methods.cpp @@ -175,6 +175,7 @@ U_CFUNC PHP_FUNCTION(intlcal_get_keyword_values_for_locale) } //does not work; see ICU bug 9194 + // TODO This was fixed in ICU 50.1 see: https://unicode-org.atlassian.net/browse/ICU-9194 #if 0 StringEnumeration *se = Calendar::getKeywordValuesForLocale(key, Locale::createFromName(locale), (UBool)commonly_used, diff --git a/ext/intl/collator/collator_convert.c b/ext/intl/collator/collator_convert.c index 88177a04f6497..da2cb85673b5c 100644 --- a/ext/intl/collator/collator_convert.c +++ b/ext/intl/collator/collator_convert.c @@ -194,6 +194,7 @@ zval* collator_convert_zstr_utf8_to_utf16( zval* utf8_zval, zval *rv ) &ustr, &ustr_len, Z_STRVAL_P( utf8_zval ), Z_STRLEN_P( utf8_zval ), &status ); + // FIXME Or throw error or use intl internal error handler if( U_FAILURE( status ) ) php_error( E_WARNING, "Error casting object to string in collator_convert_zstr_utf8_to_utf16()" ); @@ -244,6 +245,7 @@ zval* collator_convert_object_to_string( zval* obj, zval *rv ) &ustr, &ustr_len, Z_STRVAL_P( zstr ), Z_STRLEN_P( zstr ), &status ); + // FIXME Or throw error or use intl internal error handler if( U_FAILURE( status ) ) php_error( E_WARNING, "Error casting object to string in collator_convert_object_to_string()" ); From da13108a8f9c3a38ff7220e5024f50dfbcc72180 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Fri, 24 Jul 2020 08:17:20 +0100 Subject: [PATCH 5/8] Drop workaround due to ICU bug 9194 This was fixed in ICU 50.1 which is required as of PHP 7.4 --- ext/intl/calendar/calendar_methods.cpp | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/ext/intl/calendar/calendar_methods.cpp b/ext/intl/calendar/calendar_methods.cpp index 822f11601e70d..c30f76ea5e381 100644 --- a/ext/intl/calendar/calendar_methods.cpp +++ b/ext/intl/calendar/calendar_methods.cpp @@ -174,9 +174,6 @@ U_CFUNC PHP_FUNCTION(intlcal_get_keyword_values_for_locale) RETURN_THROWS(); } - //does not work; see ICU bug 9194 - // TODO This was fixed in ICU 50.1 see: https://unicode-org.atlassian.net/browse/ICU-9194 -#if 0 StringEnumeration *se = Calendar::getKeywordValuesForLocale(key, Locale::createFromName(locale), (UBool)commonly_used, status); @@ -185,18 +182,6 @@ U_CFUNC PHP_FUNCTION(intlcal_get_keyword_values_for_locale) "error calling underlying method", 0); RETURN_FALSE; } -#else - UEnumeration *uenum = ucal_getKeywordValuesForLocale( - key, locale, !!commonly_used, &status); - if (U_FAILURE(status)) { - uenum_close(uenum); - intl_error_set(NULL, status, "intlcal_get_keyword_values_for_locale: " - "error calling underlying method", 0); - RETURN_FALSE; - } - - StringEnumeration *se = new BugStringCharEnumeration(uenum); -#endif IntlIterator_from_StringEnumeration(se, return_value); } From dd3bbb4cd94be23128e452305938d1f9951db549 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Fri, 24 Jul 2020 19:27:10 +0100 Subject: [PATCH 6/8] Nits --- ext/intl/calendar/calendar_methods.cpp | 19 +++++++------------ .../calendar/gregoriancalendar_methods.cpp | 4 ++-- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/ext/intl/calendar/calendar_methods.cpp b/ext/intl/calendar/calendar_methods.cpp index c30f76ea5e381..2d852440d3a4b 100644 --- a/ext/intl/calendar/calendar_methods.cpp +++ b/ext/intl/calendar/calendar_methods.cpp @@ -347,11 +347,9 @@ static void _php_intlcal_before_after( CALENDAR_METHOD_FETCH_OBJECT; when_co = Z_INTL_CALENDAR_P(when_object); - /* Can this ever happen ? */ if (when_co->ucal == NULL) { - intl_errors_set(&co->err, U_ILLEGAL_ARGUMENT_ERROR, - "intlcal_before/after: Other IntlCalendar was unconstructed", 0); - RETURN_FALSE; + zend_argument_error(NULL, 2, "object is not fully initialized"); + RETURN_THROWS(); } UBool res = (co->ucal->*func)(*when_co->ucal, CALENDAR_ERROR_CODE(co)); @@ -716,11 +714,9 @@ U_CFUNC PHP_FUNCTION(intlcal_is_equivalent_to) } other_co = Z_INTL_CALENDAR_P(other_object); - // Can this happen? if (other_co->ucal == NULL) { - intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlcal_is_equivalent_to:" - " Other IntlCalendar is unconstructed", 0); - RETURN_FALSE; + zend_argument_error(NULL, 2, "object is not fully initialized"); + RETURN_THROWS(); } CALENDAR_METHOD_FETCH_OBJECT; @@ -856,11 +852,9 @@ U_CFUNC PHP_FUNCTION(intlcal_equals) CALENDAR_METHOD_FETCH_OBJECT; other_co = Z_INTL_CALENDAR_P(other_object); - // Can this happen? if (other_co->ucal == NULL) { - intl_errors_set(&co->err, U_ILLEGAL_ARGUMENT_ERROR, - "intlcal_equals: The second IntlCalendar is unconstructed", 0); - RETURN_FALSE; + zend_argument_error(NULL, 2, "object is not fully initialized"); + RETURN_THROWS(); } UBool result = co->ucal->equals(*other_co->ucal, CALENDAR_ERROR_CODE(co)); @@ -1085,6 +1079,7 @@ U_CFUNC PHP_FUNCTION(intlcal_to_date_time) object_init_ex(return_value, php_date_get_date_ce()); zend_call_known_instance_method_with_2_params( Z_OBJCE_P(return_value)->constructor, Z_OBJ_P(return_value), NULL, &ts_zval, timezone_zval); + // TODO Bubble up exception? if (EG(exception)) { intl_errors_set(CALENDAR_ERROR_P(co), U_ILLEGAL_ARGUMENT_ERROR, "intlcal_to_date_time: DateTime constructor has thrown exception", diff --git a/ext/intl/calendar/gregoriancalendar_methods.cpp b/ext/intl/calendar/gregoriancalendar_methods.cpp index 3b7bbd165474f..84d594185c46f 100644 --- a/ext/intl/calendar/gregoriancalendar_methods.cpp +++ b/ext/intl/calendar/gregoriancalendar_methods.cpp @@ -125,7 +125,7 @@ static void _php_intlgregcal_constructor_body( // From date/time (3, 5 or 6 arguments) for (int i = 0; i < variant; i++) { if (largs[i] < INT32_MIN || largs[i] > INT32_MAX) { - zend_argument_value_error(getThis() ? (i-1):i, + zend_argument_value_error(getThis() ? (i-1) : i, "must be between %d and %d", INT32_MIN, INT32_MAX); RETURN_THROWS(); } @@ -240,7 +240,7 @@ U_CFUNC PHP_FUNCTION(intlgregcal_is_leap_year) } if (year < INT32_MIN || year > INT32_MAX) { - zend_argument_value_error(getThis() ? 1:2, "must be between %d and %d", INT32_MIN, INT32_MAX); + zend_argument_value_error(getThis() ? 1 : 2, "must be between %d and %d", INT32_MIN, INT32_MAX); RETURN_THROWS(); } From cacb1433f845d55fb7c8469a553a447476e93fd0 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Wed, 29 Jul 2020 17:15:09 +0100 Subject: [PATCH 7/8] Fix error message --- ext/intl/calendar/calendar_methods.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ext/intl/calendar/calendar_methods.cpp b/ext/intl/calendar/calendar_methods.cpp index 2d852440d3a4b..9f56527dfbd57 100644 --- a/ext/intl/calendar/calendar_methods.cpp +++ b/ext/intl/calendar/calendar_methods.cpp @@ -348,7 +348,7 @@ static void _php_intlcal_before_after( when_co = Z_INTL_CALENDAR_P(when_object); if (when_co->ucal == NULL) { - zend_argument_error(NULL, 2, "object is not fully initialized"); + zend_argument_error(NULL, 2, "is uninitialized"); RETURN_THROWS(); } @@ -715,7 +715,7 @@ U_CFUNC PHP_FUNCTION(intlcal_is_equivalent_to) other_co = Z_INTL_CALENDAR_P(other_object); if (other_co->ucal == NULL) { - zend_argument_error(NULL, 2, "object is not fully initialized"); + zend_argument_error(NULL, 2, "is uninitialized"); RETURN_THROWS(); } @@ -853,7 +853,7 @@ U_CFUNC PHP_FUNCTION(intlcal_equals) CALENDAR_METHOD_FETCH_OBJECT; other_co = Z_INTL_CALENDAR_P(other_object); if (other_co->ucal == NULL) { - zend_argument_error(NULL, 2, "object is not fully initialized"); + zend_argument_error(NULL, 2, "is uninitialized"); RETURN_THROWS(); } From ed93fb8ca22d59a48c5c8ef4e8b6c13ed8d79f85 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Wed, 29 Jul 2020 18:08:46 +0100 Subject: [PATCH 8/8] Drop bubble up todo with warning, albeit can't seem to hit this --- ext/intl/calendar/calendar_methods.cpp | 4 -- ext/intl/tests/calendar_toDateTime_error.phpt | 39 ++++++++++++++++--- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/ext/intl/calendar/calendar_methods.cpp b/ext/intl/calendar/calendar_methods.cpp index 9f56527dfbd57..b6ef461e9e8fd 100644 --- a/ext/intl/calendar/calendar_methods.cpp +++ b/ext/intl/calendar/calendar_methods.cpp @@ -1079,11 +1079,7 @@ U_CFUNC PHP_FUNCTION(intlcal_to_date_time) object_init_ex(return_value, php_date_get_date_ce()); zend_call_known_instance_method_with_2_params( Z_OBJCE_P(return_value)->constructor, Z_OBJ_P(return_value), NULL, &ts_zval, timezone_zval); - // TODO Bubble up exception? if (EG(exception)) { - intl_errors_set(CALENDAR_ERROR_P(co), U_ILLEGAL_ARGUMENT_ERROR, - "intlcal_to_date_time: DateTime constructor has thrown exception", - 1); zend_object_store_ctor_failed(Z_OBJ_P(return_value)); zval_ptr_dtor(return_value); zval_ptr_dtor(&ts_zval); diff --git a/ext/intl/tests/calendar_toDateTime_error.phpt b/ext/intl/tests/calendar_toDateTime_error.phpt index 20f45ef6d24de..01cf75c4c2071 100644 --- a/ext/intl/tests/calendar_toDateTime_error.phpt +++ b/ext/intl/tests/calendar_toDateTime_error.phpt @@ -16,13 +16,40 @@ var_dump($cal->toDateTime()); var_dump("exception: {$e->getMessage()}"); } -var_dump(intlcal_to_date_time(3)); +try { + var_dump(intlcal_to_date_time($cal)); +} catch (\Exception $e) { + var_dump($e->getMessage()); +} + +$cal = IntlCalendar::createInstance("Etc/Unknown"); +try { + var_dump($cal->toDateTime()); +} catch (\Exception $e) { + var_dump($e->getMessage()); +} + +try { + var_dump(intlcal_to_date_time($cal)); +} catch (\Exception $e) { + var_dump($e->getMessage()); +} + +try { + var_dump(intlcal_to_date_time(3)); +} catch (\TypeError $e) { + echo $e->getMessage() . \PHP_EOL; +} --EXPECTF-- Warning: IntlCalendar::toDateTime(): intlcal_to_date_time: DateTimeZone constructor threw exception in %s on line %d string(77) "exception: DateTimeZone::__construct(): Unknown or bad timezone (Etc/Unknown)" -Fatal error: Uncaught TypeError: intlcal_to_date_time(): Argument #1 ($calendar) must be of type IntlCalendar, int given in %s:%d -Stack trace: -#0 %s(%d): intlcal_to_date_time(3) -#1 {main} - thrown in %s on line %d +Warning: intlcal_to_date_time(): intlcal_to_date_time: DateTimeZone constructor threw exception in %s on line %d +string(66) "DateTimeZone::__construct(): Unknown or bad timezone (Etc/Unknown)" + +Warning: IntlCalendar::toDateTime(): intlcal_to_date_time: DateTimeZone constructor threw exception in %s on line %d +string(66) "DateTimeZone::__construct(): Unknown or bad timezone (Etc/Unknown)" + +Warning: intlcal_to_date_time(): intlcal_to_date_time: DateTimeZone constructor threw exception in %s on line %d +string(66) "DateTimeZone::__construct(): Unknown or bad timezone (Etc/Unknown)" +intlcal_to_date_time(): Argument #1 ($calendar) must be of type IntlCalendar, int given