diff options
Diffstat (limited to 'ext/intl')
22 files changed, 273 insertions, 109 deletions
diff --git a/ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp b/ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp index c112134124..b43f8212d0 100644 --- a/ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp +++ b/ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp @@ -24,6 +24,7 @@ extern "C" { } #include "../intl_convertcpp.h" +#include "../intl_common.h" static inline RuleBasedBreakIterator *fetch_rbbi(BreakIterator_object *bio) { return (RuleBasedBreakIterator*)bio->biter; @@ -97,15 +98,17 @@ static void _php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAMETERS) U_CFUNC PHP_METHOD(IntlRuleBasedBreakIterator, __construct) { - zval orig_this = *getThis(); + zend_error_handling error_handling; + zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling); return_value = getThis(); _php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU); - if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { - zend_object_store_ctor_failed(Z_OBJ(orig_this)); - ZEND_CTOR_MAKE_NULL(); + if (!EG(exception)) { + zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0); + } } + zend_restore_error_handling(&error_handling); } U_CFUNC PHP_FUNCTION(rbbi_get_rules) diff --git a/ext/intl/calendar/gregoriancalendar_methods.cpp b/ext/intl/calendar/gregoriancalendar_methods.cpp index 2ae5737227..d9572a0668 100644 --- a/ext/intl/calendar/gregoriancalendar_methods.cpp +++ b/ext/intl/calendar/gregoriancalendar_methods.cpp @@ -25,11 +25,13 @@ #include <unicode/gregocal.h> extern "C" { #include "../php_intl.h" +#include "../intl_common.h" #define USE_TIMEZONE_POINTER 1 #include "../timezone/timezone_class.h" #define USE_CALENDAR_POINTER 1 #include "calendar_class.h" #include <ext/date/php_date.h> +#include "zend_exceptions.h" } static inline GregorianCalendar *fetch_greg(Calendar_object *co) { @@ -189,17 +191,18 @@ U_CFUNC PHP_FUNCTION(intlgregcal_create_instance) U_CFUNC PHP_METHOD(IntlGregorianCalendar, __construct) { - zval orig_this = *getThis(); - intl_error_reset(NULL); + zend_error_handling error_handling; + zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling); return_value = getThis(); //changes this to IS_NULL (without first destroying) if there's an error _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU); - if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { - zend_object_store_ctor_failed(Z_OBJ(orig_this)); - ZEND_CTOR_MAKE_NULL(); + if (!EG(exception)) { + zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0); + } } + zend_restore_error_handling(&error_handling); } U_CFUNC PHP_FUNCTION(intlgregcal_set_gregorian_change) diff --git a/ext/intl/collator/collator_create.c b/ext/intl/collator/collator_create.c index b2058422c2..c6bc3fd209 100644 --- a/ext/intl/collator/collator_create.c +++ b/ext/intl/collator/collator_create.c @@ -72,15 +72,17 @@ PHP_FUNCTION( collator_create ) */ PHP_METHOD( Collator, __construct ) { - zval orig_this = *getThis(); + zend_error_handling error_handling; + zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling); return_value = getThis(); collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); - if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { - zend_object_store_ctor_failed(Z_OBJ(orig_this)); - ZEND_CTOR_MAKE_NULL(); + if (!EG(exception)) { + zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0); + } } + zend_restore_error_handling(&error_handling); } /* }}} */ diff --git a/ext/intl/converter/converter.c b/ext/intl/converter/converter.c index 9bba427409..fd3aced34d 100644 --- a/ext/intl/converter/converter.c +++ b/ext/intl/converter/converter.c @@ -22,6 +22,7 @@ #include <unicode/ustring.h> #include "../intl_error.h" +#include "../intl_common.h" typedef struct _php_converter_object { UConverter *src, *dest; @@ -556,11 +557,17 @@ static PHP_METHOD(UConverter, __construct) { size_t src_len = sizeof("utf-8") - 1; char *dest = src; size_t dest_len = src_len; + zend_error_handling zeh; + int rv; intl_error_reset(NULL); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!s!", - &dest, &dest_len, &src, &src_len) == FAILURE) { + zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &zeh); + rv = zend_parse_parameters(ZEND_NUM_ARGS(), "|s!s!", + &dest, &dest_len, &src, &src_len); + zend_restore_error_handling(&zeh); + + if (rv == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "UConverter::__construct(): bad arguments", 0); return; diff --git a/ext/intl/dateformat/dateformat_create.cpp b/ext/intl/dateformat/dateformat_create.cpp index f8cf77641f..b7ad7b5126 100644 --- a/ext/intl/dateformat/dateformat_create.cpp +++ b/ext/intl/dateformat/dateformat_create.cpp @@ -34,6 +34,7 @@ extern "C" { } #include "dateformat_helpers.h" +#include "zend_exceptions.h" /* {{{ */ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS) @@ -187,16 +188,18 @@ U_CFUNC PHP_FUNCTION( datefmt_create ) */ U_CFUNC PHP_METHOD( IntlDateFormatter, __construct ) { - zval orig_this = *getThis(); + zend_error_handling error_handling; + zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling); /* return_value param is being changed, therefore we will always return * NULL here */ return_value = getThis(); datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); - if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { - zend_object_store_ctor_failed(Z_OBJ(orig_this)); - ZEND_CTOR_MAKE_NULL(); + if (!EG(exception)) { + zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0); + } } + zend_restore_error_handling(&error_handling); } /* }}} */ diff --git a/ext/intl/formatter/formatter_main.c b/ext/intl/formatter/formatter_main.c index 60db673ff2..5d5a139688 100644 --- a/ext/intl/formatter/formatter_main.c +++ b/ext/intl/formatter/formatter_main.c @@ -90,15 +90,17 @@ PHP_FUNCTION( numfmt_create ) */ PHP_METHOD( NumberFormatter, __construct ) { - zval orig_this = *getThis(); + zend_error_handling error_handling; + zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling); return_value = getThis(); numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); - if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { - zend_object_store_ctor_failed(Z_OBJ(orig_this)); - ZEND_CTOR_MAKE_NULL(); + if (!EG(exception)) { + zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0); + } } + zend_restore_error_handling(&error_handling); } /* }}} */ diff --git a/ext/intl/intl_common.h b/ext/intl/intl_common.h index a49794648d..61da2738d1 100644 --- a/ext/intl/intl_common.h +++ b/ext/intl/intl_common.h @@ -41,4 +41,6 @@ #define INTL_Z_STRVAL_P(str) (UChar*) Z_STRVAL_P(str) #define INTL_Z_STRLEN_P(str) UCHARS( Z_STRLEN_P(str) ) +extern zend_class_entry *IntlException_ce_ptr; + #endif /* INTL_COMMON_H */ diff --git a/ext/intl/intl_error.c b/ext/intl/intl_error.c index 28a2a244e2..a946705a76 100644 --- a/ext/intl/intl_error.c +++ b/ext/intl/intl_error.c @@ -29,7 +29,7 @@ ZEND_EXTERN_MODULE_GLOBALS( intl ) -static zend_class_entry *IntlException_ce_ptr; +zend_class_entry *IntlException_ce_ptr; /* {{{ intl_error* intl_g_error_get() * Return global error structure. diff --git a/ext/intl/msgformat/msgformat.c b/ext/intl/msgformat/msgformat.c index 707b38bd95..15d6ef8321 100644 --- a/ext/intl/msgformat/msgformat.c +++ b/ext/intl/msgformat/msgformat.c @@ -108,15 +108,17 @@ PHP_FUNCTION( msgfmt_create ) */ PHP_METHOD( MessageFormatter, __construct ) { - zval orig_this = *getThis(); + zend_error_handling error_handling; + zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling); return_value = getThis(); msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); - if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { - zend_object_store_ctor_failed(Z_OBJ(orig_this)); - ZEND_CTOR_MAKE_NULL(); + if (!EG(exception)) { + zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0); + } } + zend_restore_error_handling(&error_handling); } /* }}} */ diff --git a/ext/intl/resourcebundle/resourcebundle_class.c b/ext/intl/resourcebundle/resourcebundle_class.c index b8d27c940a..d8d1aa0d9c 100644 --- a/ext/intl/resourcebundle/resourcebundle_class.c +++ b/ext/intl/resourcebundle/resourcebundle_class.c @@ -25,6 +25,7 @@ #include "php_intl.h" #include "intl_data.h" +#include "intl_common.h" #include "resourcebundle/resourcebundle.h" #include "resourcebundle/resourcebundle_iterator.h" @@ -139,15 +140,17 @@ ZEND_END_ARG_INFO() */ PHP_METHOD( ResourceBundle, __construct ) { - zval orig_this = *getThis(); + zend_error_handling error_handling; + zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling); return_value = getThis(); resourcebundle_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); - if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { - zend_object_store_ctor_failed(Z_OBJ(orig_this)); - ZEND_CTOR_MAKE_NULL(); + if (!EG(exception)) { + zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0); + } } + zend_restore_error_handling(&error_handling); } /* }}} */ diff --git a/ext/intl/spoofchecker/spoofchecker_create.c b/ext/intl/spoofchecker/spoofchecker_create.c index d797015cf8..abe1d8e9cc 100644 --- a/ext/intl/spoofchecker/spoofchecker_create.c +++ b/ext/intl/spoofchecker/spoofchecker_create.c @@ -30,8 +30,12 @@ PHP_METHOD(Spoofchecker, __construct) { int checks; SPOOFCHECKER_METHOD_INIT_VARS; + zend_error_handling error_handling; + + zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } @@ -46,6 +50,7 @@ PHP_METHOD(Spoofchecker, __construct) */ checks = uspoof_getChecks(co->uspoof, SPOOFCHECKER_ERROR_CODE_P(co)); uspoof_setChecks(co->uspoof, checks & ~USPOOF_SINGLE_SCRIPT, SPOOFCHECKER_ERROR_CODE_P(co)); + zend_restore_error_handling(&error_handling); } /* }}} */ diff --git a/ext/intl/tests/breakiter___construct_error.phpt b/ext/intl/tests/breakiter___construct_error.phpt index 770f1403c7..bea65667fa 100644 --- a/ext/intl/tests/breakiter___construct_error.phpt +++ b/ext/intl/tests/breakiter___construct_error.phpt @@ -7,32 +7,44 @@ IntlRuleBasedBreakIterator::__construct(): arg errors <?php ini_set("intl.error_level", E_WARNING); -//missing ; at the end: -var_dump(new IntlRuleBasedBreakIterator('[\p{Letter}\uFFFD]+;[:number:]+')); -var_dump(new IntlRuleBasedBreakIterator()); -var_dump(new IntlRuleBasedBreakIterator(1,2,3)); -var_dump(new IntlRuleBasedBreakIterator('[\p{Letter}\uFFFD]+;[:number:]+;', array())); -var_dump(new IntlRuleBasedBreakIterator('[\p{Letter}\uFFFD]+;[:number:]+;', true)); +function print_exception($e) { + echo "\nException: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . "\n"; +} +//missing ; at the end: +try { + var_dump(new IntlRuleBasedBreakIterator('[\p{Letter}\uFFFD]+;[:number:]+')); +} catch (IntlException $e) { + print_exception($e); +} +try { + var_dump(new IntlRuleBasedBreakIterator()); +} catch (IntlException $e) { + print_exception($e); +} +try { + var_dump(new IntlRuleBasedBreakIterator(1,2,3)); +} catch (IntlException $e) { + print_exception($e); +} +try { + var_dump(new IntlRuleBasedBreakIterator('[\p{Letter}\uFFFD]+;[:number:]+;', array())); +} catch (IntlException $e) { + print_exception($e); +} +try { + var_dump(new IntlRuleBasedBreakIterator('[\p{Letter}\uFFFD]+;[:number:]+;', true)); +} catch (IntlException $e) { + print_exception($e); +} --EXPECTF-- -Warning: IntlRuleBasedBreakIterator::__construct(): rbbi_create_instance: unable to create RuleBasedBreakIterator from rules (parse error on line 1, offset 31) in %s on line %d -NULL - -Warning: IntlRuleBasedBreakIterator::__construct() expects at least 1 parameter, 0 given in %s on line %d - -Warning: IntlRuleBasedBreakIterator::__construct(): rbbi_create_instance: bad arguments in %s on line %d -NULL - -Warning: IntlRuleBasedBreakIterator::__construct() expects at most 2 parameters, 3 given in %s on line %d +Exception: IntlRuleBasedBreakIterator::__construct(): rbbi_create_instance: unable to create RuleBasedBreakIterator from rules (parse error on line 1, offset 31) in %s on line %d -Warning: IntlRuleBasedBreakIterator::__construct(): rbbi_create_instance: bad arguments in %s on line %d -NULL +Exception: IntlRuleBasedBreakIterator::__construct() expects at least 1 parameter, 0 given in %s on line %d -Warning: IntlRuleBasedBreakIterator::__construct() expects parameter 2 to be boolean, array given in %s on line %d +Exception: IntlRuleBasedBreakIterator::__construct() expects at most 2 parameters, 3 given in %s on line %d -Warning: IntlRuleBasedBreakIterator::__construct(): rbbi_create_instance: bad arguments in %s on line %d -NULL +Exception: IntlRuleBasedBreakIterator::__construct() expects parameter 2 to be boolean, array given in %s on line %d -Warning: IntlRuleBasedBreakIterator::__construct(): rbbi_create_instance: unable to create instance from compiled rules in %s on line %d -NULL +Exception: IntlRuleBasedBreakIterator::__construct(): rbbi_create_instance: unable to create instance from compiled rules in %s on line %d diff --git a/ext/intl/tests/bug62017.phpt b/ext/intl/tests/bug62017.phpt index 50aeae4806..2f3c816f99 100644 --- a/ext/intl/tests/bug62017.phpt +++ b/ext/intl/tests/bug62017.phpt @@ -10,13 +10,15 @@ ini_set('intl.error_level', E_WARNING); var_dump( datefmt_create('', IntlDateFormatter::NONE, IntlDateFormatter::NONE, "\xFF", IntlDateFormatter::GREGORIAN, 'a')); -var_dump( - new IntlDateFormatter('', IntlDateFormatter::NONE, IntlDateFormatter::NONE, "Europe/Lisbon", - IntlDateFormatter::GREGORIAN, "\x80")); +try { + var_dump( + new IntlDateFormatter('', IntlDateFormatter::NONE, IntlDateFormatter::NONE, "Europe/Lisbon", + IntlDateFormatter::GREGORIAN, "\x80")); +} catch (IntlException $e) { + echo PHP_EOL."Exception: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . PHP_EOL; +} --EXPECTF-- Warning: datefmt_create(): datefmt_create: Time zone identifier given is not a valid UTF-8 string in %s on line %d NULL -Warning: IntlDateFormatter::__construct(): datefmt_create: error converting pattern to UTF-16 in %s on line %d -NULL - +Exception: IntlDateFormatter::__construct(): datefmt_create: error converting pattern to UTF-16 in %sbug62017.php on line %d diff --git a/ext/intl/tests/bug62081.phpt b/ext/intl/tests/bug62081.phpt index 44ad4beec7..263023ffac 100644 --- a/ext/intl/tests/bug62081.phpt +++ b/ext/intl/tests/bug62081.phpt @@ -12,5 +12,8 @@ ini_set('intl.error_level', E_WARNING); $x = new IntlDateFormatter('en', 1, 1); var_dump($x->__construct('en', 1, 1)); --EXPECTF-- -Warning: IntlDateFormatter::__construct(): datefmt_create: cannot call constructor twice in %s on line %d -NULL +Fatal error: Uncaught exception 'IntlException' with message 'IntlDateFormatter::__construct(): datefmt_create: cannot call constructor twice' in %sbug62081.php:4 +Stack trace: +#0 %sbug62081.php(4): IntlDateFormatter->__construct('en', 1, 1) +#1 {main} + thrown in %sbug62081.php on line 4 diff --git a/ext/intl/tests/dateformat___construct_bad_tz_cal.phpt b/ext/intl/tests/dateformat___construct_bad_tz_cal.phpt index cfd9338717..d10ad42623 100644 --- a/ext/intl/tests/dateformat___construct_bad_tz_cal.phpt +++ b/ext/intl/tests/dateformat___construct_bad_tz_cal.phpt @@ -10,23 +10,32 @@ ini_set("intl.error_level", E_WARNING); ini_set("intl.default_locale", "pt_PT"); ini_set("date.timezone", 'Atlantic/Azores'); -var_dump(new IntlDateFormatter(NULL, 0, 0, 'bad timezone')); - -var_dump(new IntlDateFormatter(NULL, 0, 0, NULL, 3)); - -var_dump(new IntlDateFormatter(NULL, 0, 0, NULL, new stdclass)); - - +function print_exception($e) { + echo "\nException: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . "\n"; +} + +try { + var_dump(new IntlDateFormatter(NULL, 0, 0, 'bad timezone')); +} catch (IntlException $e) { + print_exception($e); +} +try { + var_dump(new IntlDateFormatter(NULL, 0, 0, NULL, 3)); +} catch (IntlException $e) { + print_exception($e); +} +try { + var_dump(new IntlDateFormatter(NULL, 0, 0, NULL, new stdclass)); +} catch (IntlException $e) { + print_exception($e); +} ?> ==DONE== --EXPECTF-- -Warning: IntlDateFormatter::__construct(): datefmt_create: no such time zone: 'bad timezone' in %s on line %d -NULL +Exception: IntlDateFormatter::__construct(): datefmt_create: no such time zone: 'bad timezone' in %s on line %d -Warning: IntlDateFormatter::__construct(): datefmt_create: invalid value for calendar type; it must be one of IntlDateFormatter::TRADITIONAL (locale's default calendar) or IntlDateFormatter::GREGORIAN. Alternatively, it can be an IntlCalendar object in %s on line %d -NULL +Exception: IntlDateFormatter::__construct(): datefmt_create: invalid value for calendar type; it must be one of IntlDateFormatter::TRADITIONAL (locale's default calendar) or IntlDateFormatter::GREGORIAN. Alternatively, it can be an IntlCalendar object in %s on line %d -Warning: IntlDateFormatter::__construct(): datefmt_create: Invalid calendar argument; should be an integer or an IntlCalendar instance in %s on line %d -NULL +Exception: IntlDateFormatter::__construct(): datefmt_create: Invalid calendar argument; should be an integer or an IntlCalendar instance in %s on line %d ==DONE== diff --git a/ext/intl/tests/dateformat_calendars.phpt b/ext/intl/tests/dateformat_calendars.phpt index 7de6356455..13dde0f370 100644 --- a/ext/intl/tests/dateformat_calendars.phpt +++ b/ext/intl/tests/dateformat_calendars.phpt @@ -41,5 +41,8 @@ string(44) "Sunday, January 1, 2012 5:12:00 AM GMT+05:12" string(44) "Sunday, January 1, 2012 5:12:00 AM GMT+05:12" string(42) "Sunday, Tevet 6, 5772 5:12:00 AM GMT+05:12" -Warning: IntlDateFormatter::__construct(): datefmt_create: invalid value for calendar type; it must be one of IntlDateFormatter::TRADITIONAL (locale's default calendar) or IntlDateFormatter::GREGORIAN. Alternatively, it can be an IntlCalendar object in %s on line %d -==DONE== +Fatal error: Uncaught exception 'IntlException' with message 'IntlDateFormatter::__construct(): datefmt_create: invalid value for calendar type; it must be one of IntlDateFormatter::TRADITIONAL (locale's default calendar) or IntlDateFormatter::GREGORIAN. Alternatively, it can be an IntlCalendar object' in %sdateformat_calendars.php:%d +Stack trace: +#0 %sdateformat_calendars.php(%d): IntlDateFormatter->__construct('en_US@calendar=...', 0, 0, 'GMT+05:12', -1) +#1 {main} + thrown in %sdateformat_calendars.php on line %d diff --git a/ext/intl/tests/dateformat_calendars_variant2.phpt b/ext/intl/tests/dateformat_calendars_variant2.phpt index b3b1701c55..11a5026da0 100644 --- a/ext/intl/tests/dateformat_calendars_variant2.phpt +++ b/ext/intl/tests/dateformat_calendars_variant2.phpt @@ -42,5 +42,8 @@ string(47) "Sunday, January 1, 2012 at 5:12:00 AM GMT+05:12" string(47) "Sunday, January 1, 2012 at 5:12:00 AM GMT+05:12" string(48) "Sunday, Tevet 6, 5772 AM at 5:12:00 AM GMT+05:12" -Warning: IntlDateFormatter::__construct(): datefmt_create: invalid value for calendar type; it must be one of IntlDateFormatter::TRADITIONAL (locale's default calendar) or IntlDateFormatter::GREGORIAN. Alternatively, it can be an IntlCalendar object in %sdateformat_calendars_variant2.php on line %d -==DONE== +Fatal error: Uncaught exception 'IntlException' with message 'IntlDateFormatter::__construct(): datefmt_create: invalid value for calendar type; it must be one of IntlDateFormatter::TRADITIONAL (locale's default calendar) or IntlDateFormatter::GREGORIAN. Alternatively, it can be an IntlCalendar object' in %sdateformat_calendars_variant2.php:27 +Stack trace: +#0 %sdateformat_calendars_variant2.php(27): IntlDateFormatter->__construct('en_US@calendar=...', 0, 0, 'GMT+05:12', -1) +#1 {main} + thrown in %sdateformat_calendars_variant2.php on line 27 diff --git a/ext/intl/tests/formatter_fail.phpt b/ext/intl/tests/formatter_fail.phpt index 295f011008..f61cb14878 100644 --- a/ext/intl/tests/formatter_fail.phpt +++ b/ext/intl/tests/formatter_fail.phpt @@ -11,10 +11,19 @@ function err($fmt) { } } +function print_exception($e) { + echo "\nException: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . "\n"; +} + function crt($t, $l, $s) { switch(true) { case $t == "O": - return new NumberFormatter($l, $s); + try { + return new NumberFormatter($l, $s); + } catch (IntlException $e) { + print_exception($e); + return null; + } break; case $t == "C": return NumberFormatter::create($l, $s); @@ -33,7 +42,12 @@ $args = array( array("en_US", NumberFormatter::PATTERN_RULEBASED), ); -$fmt = new NumberFormatter(); +try { + $fmt = new NumberFormatter(); +} catch (IntlException $e) { + print_exception($e); + $fmt = null; +} err($fmt); $fmt = numfmt_create(); err($fmt); @@ -51,7 +65,7 @@ foreach($args as $arg) { ?> --EXPECTF-- -Warning: NumberFormatter::__construct() expects at least 2 parameters, 0 given in %s on line %d +Exception: NumberFormatter::__construct() expects at least 2 parameters, 0 given in %s on line %d 'numfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' Warning: numfmt_create() expects at least 2 parameters, 0 given in %s on line %d @@ -59,11 +73,13 @@ Warning: numfmt_create() expects at least 2 parameters, 0 given in %s on line %d Warning: NumberFormatter::create() expects at least 2 parameters, 0 given in %s on line %d 'numfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' + +Exception: Constructor failed in %sformatter_fail.php on line %d 'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR' 'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR' 'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR' -Warning: NumberFormatter::__construct() expects parameter 1 to be string, array given in %s on line %d +Exception: NumberFormatter::__construct() expects parameter 1 to be string, array given in %s on line %d 'numfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' Warning: NumberFormatter::create() expects parameter 1 to be string, array given in %s on line %d @@ -71,9 +87,13 @@ Warning: NumberFormatter::create() expects parameter 1 to be string, array given Warning: numfmt_create() expects parameter 1 to be string, array given in %s on line %d 'numfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' + +Exception: Constructor failed in %sformatter_fail.php on line %d 'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR' 'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR' 'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR' + +Exception: Constructor failed in %sformatter_fail.php on line %d 'numfmt_create: number formatter creation failed: U_MEMORY_ALLOCATION_ERROR' 'numfmt_create: number formatter creation failed: U_MEMORY_ALLOCATION_ERROR' 'numfmt_create: number formatter creation failed: U_MEMORY_ALLOCATION_ERROR' diff --git a/ext/intl/tests/gregoriancalendar___construct_error.phpt b/ext/intl/tests/gregoriancalendar___construct_error.phpt index 45229cf000..d81809793e 100644 --- a/ext/intl/tests/gregoriancalendar___construct_error.phpt +++ b/ext/intl/tests/gregoriancalendar___construct_error.phpt @@ -8,13 +8,23 @@ if (!extension_loaded('intl')) <?php ini_set("intl.error_level", E_WARNING); +function print_exception($e) { + echo "\nException: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . "\n"; +} + var_dump(intlgregcal_create_instance(1,2,3,4,5,6,7)); var_dump(intlgregcal_create_instance(1,2,3,4,5,6,7,8)); var_dump(intlgregcal_create_instance(1,2,3,4)); -var_dump(new IntlGregorianCalendar(1,2,NULL,4)); -var_dump(new IntlGregorianCalendar(1,2,3,4,NULL,array())); - - +try { + var_dump(new IntlGregorianCalendar(1,2,NULL,4)); +} catch (IntlException $e) { + print_exception($e); +} +try { + var_dump(new IntlGregorianCalendar(1,2,3,4,NULL,array())); +} catch (IntlException $e) { + print_exception($e); +} --EXPECTF-- Warning: intlgregcal_create_instance(): intlgregcal_create_instance: too many arguments in %s on line %d @@ -26,10 +36,6 @@ NULL Warning: intlgregcal_create_instance(): intlgregcal_create_instance: no variant with 4 arguments (excluding trailing NULLs) in %s on line %d NULL -Warning: IntlGregorianCalendar::__construct(): intlgregcal_create_instance: no variant with 4 arguments (excluding trailing NULLs) in %s on line %d -NULL - -Warning: IntlGregorianCalendar::__construct() expects parameter 6 to be integer, array given in %s on line %d +Exception: IntlGregorianCalendar::__construct(): intlgregcal_create_instance: no variant with 4 arguments (excluding trailing NULLs) in %s on line %d -Warning: IntlGregorianCalendar::__construct(): intlgregcal_create_instance: bad arguments in %s on line %d -NULL +Exception: IntlGregorianCalendar::__construct() expects parameter 6 to be integer, array given in %s on line %d diff --git a/ext/intl/tests/msgfmt_fail.phpt b/ext/intl/tests/msgfmt_fail.phpt index bffb71c56d..7c76598c0d 100644 --- a/ext/intl/tests/msgfmt_fail.phpt +++ b/ext/intl/tests/msgfmt_fail.phpt @@ -12,10 +12,19 @@ function err($fmt) { } } +function print_exception($e) { + echo "\nException: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . "\n"; +} + function crt($t, $l, $s) { switch(true) { case $t == "O": - return new MessageFormatter($l, $s); + try { + return new MessageFormatter($l, $s); + } catch (IntlException $e) { + print_exception($e); + return null; + } break; case $t == "C": return MessageFormatter::create($l, $s); @@ -35,13 +44,23 @@ $args = array( array("en_US", "\xD0"), ); -$fmt = new MessageFormatter(); +try { + $fmt = new MessageFormatter(); +} catch (IntlException $e) { + print_exception($e); + $fmt = null; +} err($fmt); $fmt = msgfmt_create(); err($fmt); $fmt = MessageFormatter::create(); -err($fmt); -$fmt = new MessageFormatter('en'); +err($fmt); +try { + $fmt = new MessageFormatter('en'); +} catch (IntlException $e) { + print_exception($e); + $fmt = null; +} err($fmt); $fmt = msgfmt_create('en'); err($fmt); @@ -59,7 +78,7 @@ foreach($args as $arg) { ?> --EXPECTF-- -Warning: MessageFormatter::__construct() expects exactly 2 parameters, 0 given in %s on line %d +Exception: MessageFormatter::__construct() expects exactly 2 parameters, 0 given in %s on line %d 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' Warning: msgfmt_create() expects exactly 2 parameters, 0 given in %s on line %d @@ -68,7 +87,7 @@ Warning: msgfmt_create() expects exactly 2 parameters, 0 given in %s on line %d Warning: MessageFormatter::create() expects exactly 2 parameters, 0 given in %s on line %d 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' -Warning: MessageFormatter::__construct() expects exactly 2 parameters, 1 given in %s on line %d +Exception: MessageFormatter::__construct() expects exactly 2 parameters, 1 given in %s on line %d 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' Warning: msgfmt_create() expects exactly 2 parameters, 1 given in %s on line %d @@ -76,14 +95,18 @@ Warning: msgfmt_create() expects exactly 2 parameters, 1 given in %s on line %d Warning: MessageFormatter::create() expects exactly 2 parameters, 1 given in %s on line %d 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' + +Exception: Constructor failed in %smsgfmt_fail2.php on line %d 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' + +Exception: Constructor failed in %smsgfmt_fail2.php on line %d 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' -Warning: MessageFormatter::__construct() expects parameter 1 to be string, array given in %s on line %d +Exception: MessageFormatter::__construct() expects parameter 1 to be string, array given in %s on line %d 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' Warning: MessageFormatter::create() expects parameter 1 to be string, array given in %s on line %d @@ -91,12 +114,18 @@ Warning: MessageFormatter::create() expects parameter 1 to be string, array give Warning: msgfmt_create() expects parameter 1 to be string, array given in %s on line %d 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' + +Exception: Constructor failed in %smsgfmt_fail2.php on line %d 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' + +Exception: Constructor failed in %smsgfmt_fail2.php on line %d 'msgfmt_create: message formatter creation failed: U_UNMATCHED_BRACES' 'msgfmt_create: message formatter creation failed: U_UNMATCHED_BRACES' 'msgfmt_create: message formatter creation failed: U_UNMATCHED_BRACES' + +Exception: Constructor failed in %smsgfmt_fail2.php on line %d 'msgfmt_create: error converting pattern to UTF-16: U_INVALID_CHAR_FOUND' 'msgfmt_create: error converting pattern to UTF-16: U_INVALID_CHAR_FOUND' 'msgfmt_create: error converting pattern to UTF-16: U_INVALID_CHAR_FOUND' diff --git a/ext/intl/tests/msgfmt_fail2.phpt b/ext/intl/tests/msgfmt_fail2.phpt index eee2424a50..0ab99cf633 100644 --- a/ext/intl/tests/msgfmt_fail2.phpt +++ b/ext/intl/tests/msgfmt_fail2.phpt @@ -12,10 +12,19 @@ function err($fmt) { } } +function print_exception($e) { + echo "\nException: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . "\n"; +} + function crt($t, $l, $s) { switch(true) { case $t == "O": - return new MessageFormatter($l, $s); + try { + return new MessageFormatter($l, $s); + } catch (IntlException $e) { + print_exception($e); + return null; + } break; case $t == "C": return MessageFormatter::create($l, $s); @@ -35,13 +44,23 @@ $args = array( array("en_US", "\xD0"), ); -$fmt = new MessageFormatter(); +try { + $fmt = new MessageFormatter(); +} catch (IntlException $e) { + print_exception($e); + $fmt = null; +} err($fmt); $fmt = msgfmt_create(); err($fmt); $fmt = MessageFormatter::create(); -err($fmt); -$fmt = new MessageFormatter('en'); +err($fmt); +try { + $fmt = new MessageFormatter('en'); +} catch (IntlException $e) { + print_exception($e); + $fmt = null; +} err($fmt); $fmt = msgfmt_create('en'); err($fmt); @@ -59,7 +78,7 @@ foreach($args as $arg) { ?> --EXPECTF-- -Warning: MessageFormatter::__construct() expects exactly 2 parameters, 0 given in %s on line %d +Exception: MessageFormatter::__construct() expects exactly 2 parameters, 0 given in %s on line %d 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' Warning: msgfmt_create() expects exactly 2 parameters, 0 given in %s on line %d @@ -68,7 +87,7 @@ Warning: msgfmt_create() expects exactly 2 parameters, 0 given in %s on line %d Warning: MessageFormatter::create() expects exactly 2 parameters, 0 given in %s on line %d 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' -Warning: MessageFormatter::__construct() expects exactly 2 parameters, 1 given in %s on line %d +Exception: MessageFormatter::__construct() expects exactly 2 parameters, 1 given in %s on line %d 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' Warning: msgfmt_create() expects exactly 2 parameters, 1 given in %s on line %d @@ -76,14 +95,18 @@ Warning: msgfmt_create() expects exactly 2 parameters, 1 given in %s on line %d Warning: MessageFormatter::create() expects exactly 2 parameters, 1 given in %s on line %d 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' + +Exception: Constructor failed in %smsgfmt_fail2.php on line %d 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' + +Exception: Constructor failed in %smsgfmt_fail2.php on line %d 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' -Warning: MessageFormatter::__construct() expects parameter 1 to be string, array given in %s on line %d +Exception: MessageFormatter::__construct() expects parameter 1 to be string, array given in %s on line %d 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' Warning: MessageFormatter::create() expects parameter 1 to be string, array given in %s on line %d @@ -91,12 +114,18 @@ Warning: MessageFormatter::create() expects parameter 1 to be string, array give Warning: msgfmt_create() expects parameter 1 to be string, array given in %s on line %d 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' + +Exception: Constructor failed in %smsgfmt_fail2.php on line %d 'msgfmt_create: message formatter creation failed: U_PATTERN_SYNTAX_ERROR' 'msgfmt_create: message formatter creation failed: U_PATTERN_SYNTAX_ERROR' 'msgfmt_create: message formatter creation failed: U_PATTERN_SYNTAX_ERROR' + +Exception: Constructor failed in %smsgfmt_fail2.php on line %d 'msgfmt_create: message formatter creation failed: U_UNMATCHED_BRACES' 'msgfmt_create: message formatter creation failed: U_UNMATCHED_BRACES' 'msgfmt_create: message formatter creation failed: U_UNMATCHED_BRACES' + +Exception: Constructor failed in %smsgfmt_fail2.php on line %d 'msgfmt_create: error converting pattern to UTF-16: U_INVALID_CHAR_FOUND' 'msgfmt_create: error converting pattern to UTF-16: U_INVALID_CHAR_FOUND' 'msgfmt_create: error converting pattern to UTF-16: U_INVALID_CHAR_FOUND' diff --git a/ext/intl/tests/ut_common.inc b/ext/intl/tests/ut_common.inc index 09be22bf5a..9f72bacae4 100644 --- a/ext/intl/tests/ut_common.inc +++ b/ext/intl/tests/ut_common.inc @@ -132,7 +132,15 @@ function ut_coll_set_default( $coll ) function ut_nfmt_create( $locale, $style, $pattern = null ) { - return $GLOBALS['oo-mode'] ? new NumberFormatter( $locale, $style, $pattern ) : numfmt_create( $locale, $style, $pattern ); + if ($GLOBALS['oo-mode']) { + try { + return new NumberFormatter( $locale, $style, $pattern ); + } catch (Exception $e) { + return NULL; + } + } else { + return numfmt_create( $locale, $style, $pattern ); + } } function ut_nfmt_format( $fmt, $number, $type = null ) { @@ -392,7 +400,15 @@ function ut_datefmt_localtime( $fmt , $value , &$parse_pos=0 ) function ut_resourcebundle_create( $locale, $bundle, $fallback=true ) { - return $GLOBALS['oo-mode'] ? new ResourceBundle($locale, $bundle, $fallback): resourcebundle_create($locale, $bundle, $fallback); + if ($GLOBALS['oo-mode']) { + try { + return new ResourceBundle($locale, $bundle, $fallback); + } catch (Exception $e) { + return NULL; + } + } else { + return resourcebundle_create($locale, $bundle, $fallback); + } } function ut_resourcebundle_count($bundle ) { |