From e3ffc8f47dad39067e74599804f1cdd82903380b Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Sat, 7 Dec 2019 02:36:27 +0100 Subject: [PATCH] Change warnings to Errors in Date extension --- Zend/tests/bug54043.phpt | 8 +-- ext/date/php_date.c | 61 ++++++++++--------- ext/date/php_date.stub.php | 2 +- ext/date/php_date_arginfo.h | 2 +- ext/date/tests/005.phpt | 55 ++++++++++------- .../tests/DatePeriod_wrong_constructor.phpt | 14 ++--- ...eriod_wrong_recurrence_on_constructor.phpt | 10 +-- ext/date/tests/bug44562.phpt | 4 +- ext/date/tests/bug45866.phpt | 11 +++- ext/date/tests/bug50055.phpt | 23 ++++--- ext/date/tests/bug52808.phpt | 11 ++-- ext/date/tests/bug54283.phpt | 4 +- ext/date/tests/bug62500.phpt | 6 +- ext/date/tests/bug67118.phpt | 2 +- ext/date/tests/bug67118_2.phpt | 5 +- ext/date/tests/bug70277.phpt | 27 ++++---- .../tests/date_default_timezone_get-4.phpt | 11 ++-- ...terval_create_from_date_string_broken.phpt | 14 +++-- ...val_create_from_date_string_nullparam.phpt | 14 +++-- ext/date/tests/ini_set_incorrect.phpt | 10 ++- ext/date/tests/oo_001.phpt | 12 ++-- .../tests/calendar_fromDateTime_error.phpt | 7 ++- ext/intl/tests/calendar_toDateTime_error.phpt | 14 ++--- .../tests/dateformat_invalid_timezone.phpt | 6 +- .../tests/timezone_toDateTimeZone_error.phpt | 13 +--- 25 files changed, 191 insertions(+), 155 deletions(-) diff --git a/Zend/tests/bug54043.phpt b/Zend/tests/bug54043.phpt index a8bbcf68cb32a..b1d339de997ef 100644 --- a/Zend/tests/bug54043.phpt +++ b/Zend/tests/bug54043.phpt @@ -1,5 +1,5 @@ --TEST-- -Bug #54043: Remove inconsitency of internal exceptions and user defined exceptions +Bug #54043: Remove inconsistency of internal exceptions and user defined exceptions --FILE-- getMessage()); +} catch (\Error $e) { + echo get_class($e) . ': ' . $e->getMessage() . \PHP_EOL; } var_dump(error_get_last()); ?> --EXPECT-- -string(105) "DateTime::__construct(): Failed to parse time string (9999-11-33) at position 9 (3): Unexpected character" +Error: Failed to parse time string (9999-11-33) at position 9 (3): Unexpected character NULL diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 7dcc212e21060..5db98fd6d5b24 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -650,7 +650,8 @@ static PHP_INI_MH(OnUpdate_date_timezone) if (stage == PHP_INI_STAGE_RUNTIME) { if (!timelib_timezone_id_is_valid(DATEG(default_timezone), DATE_TIMEZONEDB)) { if (DATEG(default_timezone) && *DATEG(default_timezone)) { - php_error_docref(NULL, E_WARNING, "Invalid date.timezone value '%s', we selected the timezone 'UTC' for now.", DATEG(default_timezone)); + zend_value_error("Invalid date.timezone value '%s'", DATEG(default_timezone)); + return FAILURE; } } else { DATEG(timezone_valid) = 1; @@ -683,7 +684,7 @@ static char* guess_timezone(const timelib_tzdb *tzdb) } if (!timelib_timezone_id_is_valid(DATEG(default_timezone), tzdb)) { - php_error_docref(NULL, E_WARNING, "Invalid date.timezone value '%s', we selected the timezone 'UTC' for now.", DATEG(default_timezone)); + zend_value_error("Invalid date.timezone value '%s'", DATEG(default_timezone)); return "UTC"; } @@ -702,7 +703,7 @@ PHPAPI timelib_tzinfo *get_timezone_info(void) tz = guess_timezone(DATE_TIMEZONEDB); tzi = php_date_parse_tzfile(tz, DATE_TIMEZONEDB); if (! tzi) { - php_error_docref(NULL, E_ERROR, "Timezone database is corrupt - this should *never* happen!"); + zend_throw_error(NULL, "Timezone database is corrupt - this should *never* happen!"); } return tzi; } @@ -1099,8 +1100,8 @@ PHP_FUNCTION(idate) ZEND_PARSE_PARAMETERS_END(); if (ZSTR_LEN(format) != 1) { - php_error_docref(NULL, E_WARNING, "idate format is one char"); - RETURN_FALSE; + zend_value_error("idate format is one char"); + return; } if (ZEND_NUM_ARGS() == 1) { @@ -1109,8 +1110,8 @@ PHP_FUNCTION(idate) ret = php_idate(ZSTR_VAL(format)[0], ts, 0); if (ret == -1) { - php_error_docref(NULL, E_WARNING, "Unrecognized date format token."); - RETURN_FALSE; + zend_value_error("Unrecognized date format token"); + return; } RETURN_LONG(ret); } @@ -1897,7 +1898,7 @@ static int date_object_compare_date(zval *d1, zval *d2) /* {{{ */ o2 = Z_PHPDATE_P(d2); if (!o1->time || !o2->time) { - php_error_docref(NULL, E_WARNING, "Trying to compare an incomplete DateTime or DateTimeImmutable object"); + zend_throw_error(NULL, "Trying to compare an incomplete DateTime or DateTimeImmutable object"); return 1; } if (!o1->time->sse_uptodate) { @@ -2324,7 +2325,7 @@ PHPAPI int php_date_initialize(php_date_obj *dateobj, /*const*/ char *time_str, if (ctor && err && err->error_count) { /* spit out the first library error message, at least */ - php_error_docref(NULL, E_WARNING, "Failed to parse time string (%s) at position %d (%c): %s", time_str, + zend_throw_error(NULL, "Failed to parse time string (%s) at position %d (%c): %s", time_str, err->error_messages[0].position, err->error_messages[0].character, err->error_messages[0].message); } if (err && err->error_count) { @@ -2855,7 +2856,7 @@ static int php_date_modify(zval *object, char *modify, size_t modify_len) /* {{{ dateobj = Z_PHPDATE_P(object); if (!(dateobj->time)) { - php_error_docref(NULL, E_WARNING, "The DateTime object has not been correctly initialized by its constructor"); + zend_throw_error(NULL, "The DateTime object has not been correctly initialized by its constructor"); return 0; } @@ -2865,7 +2866,7 @@ static int php_date_modify(zval *object, char *modify, size_t modify_len) /* {{{ update_errors_warnings(err); if (err && err->error_count) { /* spit out the first library error message, at least */ - php_error_docref(NULL, E_WARNING, "Failed to parse time string (%s) at position %d (%c): %s", modify, + zend_throw_error(NULL, "Failed to parse time string (%s) at position %d (%c): %s", modify, err->error_messages[0].position, err->error_messages[0].character, err->error_messages[0].message); timelib_time_dtor(tmp_time); return 0; @@ -3022,7 +3023,7 @@ static void php_date_sub(zval *object, zval *interval, zval *return_value) /* {{ DATE_CHECK_INITIALIZED(intobj->initialized, DateInterval); if (intobj->diff->have_special_relative) { - php_error_docref(NULL, E_WARNING, "Only non-special relative time specifications are supported for subtraction"); + zend_throw_error(NULL, "Only non-special relative time specifications are supported for subtraction"); return; } @@ -3474,14 +3475,14 @@ static int timezone_initialize(php_timezone_obj *tzobj, /*const*/ char *tz, size char *orig_tz = tz; if (strlen(tz) != tz_len) { - php_error_docref(NULL, E_WARNING, "Timezone must not contain null bytes"); + zend_value_error("Timezone must not contain null bytes"); efree(dummy_t); return FAILURE; } dummy_t->z = timelib_parse_zone(&tz, &dst, dummy_t, ¬_found, DATE_TIMEZONEDB, php_date_parse_tzfile_wrapper); if (not_found) { - php_error_docref(NULL, E_WARNING, "Unknown or bad timezone (%s)", orig_tz); + zend_value_error("Unknown or bad timezone (%s)", orig_tz); efree(dummy_t); return FAILURE; } else { @@ -3792,7 +3793,7 @@ static int date_interval_initialize(timelib_rel_time **rt, /*const*/ char *forma timelib_strtointerval(format, format_length, &b, &e, &p, &r, &errors); if (errors->error_count > 0) { - php_error_docref(NULL, E_WARNING, "Unknown or bad format (%s)", format); + zend_value_error("Unknown or bad format (%s)", format); retval = FAILURE; } else { if(p) { @@ -3805,7 +3806,7 @@ static int date_interval_initialize(timelib_rel_time **rt, /*const*/ char *forma *rt = timelib_diff(b, e); retval = SUCCESS; } else { - php_error_docref(NULL, E_WARNING, "Failed to parse interval (%s)", format); + zend_throw_error(NULL, "Failed to parse interval (%s)", format); retval = FAILURE; } } @@ -4097,7 +4098,7 @@ PHP_FUNCTION(date_interval_create_from_date_string) time = timelib_strtotime(ZSTR_VAL(time_str), ZSTR_LEN(time_str), &err, DATE_TIMEZONEDB, php_date_parse_tzfile_wrapper); if (err->error_count > 0) { - php_error_docref(NULL, E_WARNING, "Unknown or bad format (%s) at position %d (%c): %s", ZSTR_VAL(time_str), + zend_value_error("Unknown or bad format (%s) at position %d (%c): %s", ZSTR_VAL(time_str), err->error_messages[0].position, err->error_messages[0].character ? err->error_messages[0].character : ' ', err->error_messages[0].message); RETVAL_FALSE; goto cleanup; @@ -4215,7 +4216,7 @@ static int date_period_initialize(timelib_time **st, timelib_time **et, timelib_ timelib_strtointerval(format, format_length, &b, &e, &p, &r, &errors); if (errors->error_count > 0) { - php_error_docref(NULL, E_WARNING, "Unknown or bad format (%s)", format); + zend_value_error("Unknown or bad format (%s)", format); retval = FAILURE; } else { *st = b; @@ -4246,7 +4247,7 @@ PHP_METHOD(DatePeriod, __construct) if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "OOl|l", &start, date_ce_interface, &interval, date_ce_interval, &recurrences, &options) == FAILURE) { if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "OOO|l", &start, date_ce_interface, &interval, date_ce_interval, &end, date_ce_interface, &options) == FAILURE) { if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "s|l", &isostr, &isostr_len, &options) == FAILURE) { - php_error_docref(NULL, E_WARNING, "This constructor accepts either (DateTimeInterface, DateInterval, int) OR (DateTimeInterface, DateInterval, DateTime) OR (string) as arguments."); + zend_type_error("This constructor accepts either (DateTimeInterface, DateInterval, int) OR (DateTimeInterface, DateInterval, DateTime) OR (string) as arguments."); zend_restore_error_handling(&error_handling); return; } @@ -4259,13 +4260,16 @@ PHP_METHOD(DatePeriod, __construct) if (isostr) { date_period_initialize(&(dpobj->start), &(dpobj->end), &(dpobj->interval), &recurrences, isostr, isostr_len); if (dpobj->start == NULL) { - php_error_docref(NULL, E_WARNING, "The ISO interval '%s' did not contain a start date.", isostr); + zend_value_error("The ISO interval '%s' did not contain a start date.", isostr); + return; } if (dpobj->interval == NULL) { - php_error_docref(NULL, E_WARNING, "The ISO interval '%s' did not contain an interval.", isostr); + zend_value_error("The ISO interval '%s' did not contain an interval.", isostr); + return; } if (dpobj->end == NULL && recurrences == 0) { - php_error_docref(NULL, E_WARNING, "The ISO interval '%s' did not contain an end date or a recurrence count.", isostr); + zend_value_error("The ISO interval '%s' did not contain an end date or a recurrence count.", isostr); + return; } if (dpobj->start) { @@ -4304,7 +4308,8 @@ PHP_METHOD(DatePeriod, __construct) } if (dpobj->end == NULL && recurrences < 1) { - php_error_docref(NULL, E_WARNING, "The recurrence count '%d' is invalid. Needs to be > 0", (int) recurrences); + zend_value_error("The recurrence count '%d' is invalid. Needs to be > 0", (int) recurrences); + return; } /* options */ @@ -4447,6 +4452,7 @@ PHP_FUNCTION(timezone_identifiers_list) /* Extra validation */ if (what == PHP_DATE_TIMEZONE_PER_COUNTRY && option_len != 2) { + /* Upgrade to warning/exception? */ php_error_docref(NULL, E_NOTICE, "A two-letter ISO 3166-1 compatible country code is expected"); RETURN_FALSE; } @@ -4596,16 +4602,15 @@ static void php_do_date_sunrise_sunset(INTERNAL_FUNCTION_PARAMETERS, int calc_su case 6: break; default: - php_error_docref(NULL, E_WARNING, "invalid format"); - RETURN_FALSE; - break; + zend_value_error("Invalid format"); + return; } if (retformat != SUNFUNCS_RET_TIMESTAMP && retformat != SUNFUNCS_RET_STRING && retformat != SUNFUNCS_RET_DOUBLE) { - php_error_docref(NULL, E_WARNING, "Wrong return format given, pick one of SUNFUNCS_RET_TIMESTAMP, SUNFUNCS_RET_STRING or SUNFUNCS_RET_DOUBLE"); - RETURN_FALSE; + zend_value_error("Wrong return format given, pick one of SUNFUNCS_RET_TIMESTAMP, SUNFUNCS_RET_STRING or SUNFUNCS_RET_DOUBLE"); + return; } altitude = 90 - zenith; diff --git a/ext/date/php_date.stub.php b/ext/date/php_date.stub.php index 17d9a848f097c..08d24c9c71041 100644 --- a/ext/date/php_date.stub.php +++ b/ext/date/php_date.stub.php @@ -7,7 +7,7 @@ function strtotime(string $time, int $now = UNKNOWN): int|false {} function date(string $format, int $timestamp = UNKNOWN): string {} -function idate(string $format, int $timestamp = UNKNOWN): int|false {} +function idate(string $format, int $timestamp = UNKNOWN): int {} function gmdate(string $format, int $timestamp = UNKNOWN): string {} diff --git a/ext/date/php_date_arginfo.h b/ext/date/php_date_arginfo.h index 183e3e0d30a30..7bfdee03f8204 100644 --- a/ext/date/php_date_arginfo.h +++ b/ext/date/php_date_arginfo.h @@ -10,7 +10,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_date, 0, 1, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, timestamp, IS_LONG, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_idate, 0, 1, MAY_BE_LONG|MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_idate, 0, 1, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, format, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, timestamp, IS_LONG, 0) ZEND_END_ARG_INFO() diff --git a/ext/date/tests/005.phpt b/ext/date/tests/005.phpt index 23fff3b731ad2..150893f94e229 100644 --- a/ext/date/tests/005.phpt +++ b/ext/date/tests/005.phpt @@ -6,30 +6,43 @@ date_default_timezone_set('UTC'); $t = mktime(0,0,0, 6, 27, 2006); -var_dump(idate(1,1)); -var_dump(idate("")); -var_dump(idate(0)); +try { + var_dump(idate(1,1)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} + +try { + var_dump(idate("")); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} + +try { + var_dump(idate(0)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} var_dump(idate("B", $t)); -var_dump(idate("[", $t)); -var_dump(idate("'")); -echo "Done\n"; -?> ---EXPECTF-- -Warning: idate(): Unrecognized date format token. in %s on line %d -bool(false) +try { + var_dump(idate("[", $t)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} -Warning: idate(): idate format is one char in %s on line %d -bool(false) +try { + var_dump(idate("'")); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} -Warning: idate(): Unrecognized date format token. in %s on line %d -bool(false) +?> +--EXPECT-- +Unrecognized date format token +idate format is one char +Unrecognized date format token int(41) - -Warning: idate(): Unrecognized date format token. in %s on line %d -bool(false) - -Warning: idate(): Unrecognized date format token. in %s on line %d -bool(false) -Done +Unrecognized date format token +Unrecognized date format token diff --git a/ext/date/tests/DatePeriod_wrong_constructor.phpt b/ext/date/tests/DatePeriod_wrong_constructor.phpt index 8acdc5d38602f..0225a213b86bb 100644 --- a/ext/date/tests/DatePeriod_wrong_constructor.phpt +++ b/ext/date/tests/DatePeriod_wrong_constructor.phpt @@ -7,11 +7,11 @@ Havard Eide date.timezone=UTC --FILE-- getMessage(), "\n"; +} ?> ---EXPECTF-- -Fatal error: Uncaught Exception: DatePeriod::__construct(): This constructor accepts either (DateTimeInterface, DateInterval, int) OR (DateTimeInterface, DateInterval, DateTime) OR (string) as arguments. in %s:%d -Stack trace: -#0 %s(%d): DatePeriod->__construct() -#1 {main} - thrown in %s on line %d +--EXPECT-- +This constructor accepts either (DateTimeInterface, DateInterval, int) OR (DateTimeInterface, DateInterval, DateTime) OR (string) as arguments. diff --git a/ext/date/tests/DatePeriod_wrong_recurrence_on_constructor.phpt b/ext/date/tests/DatePeriod_wrong_recurrence_on_constructor.phpt index 715ea63dc94db..75f3076b38304 100644 --- a/ext/date/tests/DatePeriod_wrong_recurrence_on_constructor.phpt +++ b/ext/date/tests/DatePeriod_wrong_recurrence_on_constructor.phpt @@ -4,16 +4,16 @@ DatePeriod: Test wrong recurrence parameter on __construct getMessage(), "\n"; } try { new DatePeriod(new DateTime('yesterday'), new DateInterval('P1D'),-1); -} catch (Exception $exception) { +} catch (\ValueError $exception) { echo $exception->getMessage(), "\n"; } ?> ---EXPECTF-- -DatePeriod::__construct(): The recurrence count '0' is invalid. Needs to be > 0 -DatePeriod::__construct(): The recurrence count '-1' is invalid. Needs to be > 0 +--EXPECT-- +The recurrence count '0' is invalid. Needs to be > 0 +The recurrence count '-1' is invalid. Needs to be > 0 diff --git a/ext/date/tests/bug44562.phpt b/ext/date/tests/bug44562.phpt index 5610474108b2e..0d07e34a11dc0 100644 --- a/ext/date/tests/bug44562.phpt +++ b/ext/date/tests/bug44562.phpt @@ -8,7 +8,7 @@ try { $dp = new DatePeriod('2D'); } -catch ( Exception $e ) +catch (\ValueError $e ) { echo $e->getMessage(), "\n"; } @@ -24,7 +24,7 @@ foreach ( $dp as $d ) ?> --EXPECT-- -DatePeriod::__construct(): Unknown or bad format (2D) +The ISO interval '2D' did not contain a start date. string(24) "2008-07-20T22:44:53+0200" string(24) "2008-07-21T22:44:53+0200" string(24) "2008-07-22T22:44:53+0200" diff --git a/ext/date/tests/bug45866.phpt b/ext/date/tests/bug45866.phpt index a8407a6341466..20c88d69432ec 100644 --- a/ext/date/tests/bug45866.phpt +++ b/ext/date/tests/bug45866.phpt @@ -13,12 +13,17 @@ $date->modify( "61538461538 day" ); echo $date->format( 'r' ), "\n"; $date = new DateTime( '2009-07-29 16:44:23 Europe/London' ); -$date->modify( "£61538461538 day" ); + +try { + $date->modify( "£61538461538 day" ); +} catch (\Error $e) { + echo get_class($e) . ': ' . $e->getMessage() . \PHP_EOL; +} + echo $date->format( 'r' ), "\n"; ?> --EXPECTF-- Thu, 14 Aug 168488594 16:44:23 +0000 Thu, 14 Aug 168488594 16:44:23 +0000 - -Warning: DateTime::modify(): Failed to parse time string (£61538461538 day) at position 0 (%s): Unexpected character in %sbug45866.php on line 11 +Error: Failed to parse time string (£61538461538 day) at position 0 (%s): Unexpected character Wed, 29 Jul 2009 16:44:23 +0100 diff --git a/ext/date/tests/bug50055.phpt b/ext/date/tests/bug50055.phpt index 907bb93e44d26..ca1eb456907c9 100644 --- a/ext/date/tests/bug50055.phpt +++ b/ext/date/tests/bug50055.phpt @@ -9,7 +9,12 @@ $ds1 = date_create( $now ); $i = DateInterval::createFromDateString('third Tuesday of next month'); echo $da1->format( DateTime::ISO8601 ), "\n"; echo date_add($da1, $i)->format( DateTime::ISO8601 ), "\n"; -date_sub($ds1, $i); + +try { + date_sub($ds1, $i); +} catch (\Error $e) { + echo get_class($e) . ': ' . $e->getMessage() . \PHP_EOL; +} //negative DateInterval $da2 = date_create( $now ); @@ -17,14 +22,18 @@ $ds2 = date_create( $now ); $i2 = DateInterval::createFromDateString('third Tuesday of last month'); echo $da2->format( DateTime::ISO8601 ), "\n"; echo date_add($da2, $i2)->format( DateTime::ISO8601 ), "\n";//works -date_sub($ds2, $i); + +try { + date_sub($ds2, $i); +} catch (\Error $e) { + echo get_class($e) . ': ' . $e->getMessage() . \PHP_EOL; +} + ?> ---EXPECTF-- +--EXPECT-- 2010-03-07T13:21:38+0000 2010-04-20T13:21:38+0000 - -Warning: date_sub(): Only non-special relative time specifications are supported for subtraction in %sbug50055.php on line 9 +Error: Only non-special relative time specifications are supported for subtraction 2010-03-07T13:21:38+0000 2010-02-16T13:21:38+0000 - -Warning: date_sub(): Only non-special relative time specifications are supported for subtraction in %sbug50055.php on line 17 +Error: Only non-special relative time specifications are supported for subtraction diff --git a/ext/date/tests/bug52808.phpt b/ext/date/tests/bug52808.phpt index 810874858f6af..ce81947fd399e 100644 --- a/ext/date/tests/bug52808.phpt +++ b/ext/date/tests/bug52808.phpt @@ -17,12 +17,12 @@ foreach($intervals as $iv) { $di = new DateInterval($iv); var_dump($di); } - catch ( Exception $e ) + catch ( \Error $e ) { echo $e->getMessage(), "\n"; } } -echo "==DONE==\n"; + ?> --EXPECTF-- object(DateInterval)#%d (16) { @@ -127,7 +127,6 @@ object(DateInterval)#%d (16) { ["have_special_relative"]=> int(0) } -DateInterval::__construct(): Failed to parse interval (2007-05-11T15:30:00Z/) -DateInterval::__construct(): Failed to parse interval (2007-05-11T15:30:00Z) -DateInterval::__construct(): Unknown or bad format (2007-05-11T15:30:00Z/:00Z) -==DONE== +Failed to parse interval (2007-05-11T15:30:00Z/) +Failed to parse interval (2007-05-11T15:30:00Z) +Unknown or bad format (2007-05-11T15:30:00Z/:00Z) diff --git a/ext/date/tests/bug54283.phpt b/ext/date/tests/bug54283.phpt index 9a8a07ce5ab50..f780339153868 100644 --- a/ext/date/tests/bug54283.phpt +++ b/ext/date/tests/bug54283.phpt @@ -5,10 +5,10 @@ Bug #54283 (new DatePeriod(NULL) causes crash) try { var_dump(new DatePeriod(NULL)); -} catch (Exception $e) { +} catch (\Error $e) { var_dump($e->getMessage()); } ?> --EXPECT-- -string(51) "DatePeriod::__construct(): Unknown or bad format ()" +string(49) "The ISO interval '' did not contain a start date." diff --git a/ext/date/tests/bug62500.phpt b/ext/date/tests/bug62500.phpt index 3afa7a561b5fc..a6a0f7d175843 100644 --- a/ext/date/tests/bug62500.phpt +++ b/ext/date/tests/bug62500.phpt @@ -16,8 +16,8 @@ class Crasher extends DateInterval { } try { $c = new Crasher('blah'); -} catch (Exception $e) { - var_dump($e->getMessage()); +} catch (\Error $e) { + echo $e->getMessage(); } --EXPECTF-- NULL @@ -25,4 +25,4 @@ int(3) Warning: Undefined property: Crasher::$2 in %s on line %d NULL -string(%s) "DateInterval::__construct(): Unknown or bad format (blah)" +Unknown or bad format (blah) diff --git a/ext/date/tests/bug67118.phpt b/ext/date/tests/bug67118.phpt index 5a7d2d1d076f6..5a8e59385c6a8 100644 --- a/ext/date/tests/bug67118.phpt +++ b/ext/date/tests/bug67118.phpt @@ -13,7 +13,7 @@ class mydt extends datetime } try { @parent::__construct($time, $tz); - } catch (Exception $e) { + } catch (\Error $e) { echo "Bad date" . $this->format("Y") . "\n"; } } diff --git a/ext/date/tests/bug67118_2.phpt b/ext/date/tests/bug67118_2.phpt index fcd7037868f97..a940af64ec31a 100644 --- a/ext/date/tests/bug67118_2.phpt +++ b/ext/date/tests/bug67118_2.phpt @@ -11,7 +11,7 @@ class Foo extends DateTime { echo "First try\n"; parent::__construct($time, $tz); return; - } catch (Exception $e) { + } catch (\Error $e) { echo "Second try\n"; parent::__construct($time.'C', $tz); } @@ -19,8 +19,8 @@ class Foo extends DateTime { } $date = '12 Sep 2007 15:49:12 UT'; var_dump(new Foo($date)); + ?> -Done --EXPECT-- First try Second try @@ -32,4 +32,3 @@ object(Foo)#1 (3) { ["timezone"]=> string(3) "UTC" } -Done diff --git a/ext/date/tests/bug70277.phpt b/ext/date/tests/bug70277.phpt index 648bd19c7771c..b963a4a8b067d 100644 --- a/ext/date/tests/bug70277.phpt +++ b/ext/date/tests/bug70277.phpt @@ -3,15 +3,20 @@ Bug #70277 (new DateTimeZone($foo) is ignoring text after null byte) --FILE-- ---EXPECTF-- -Warning: timezone_open(): Timezone must not contain null bytes in %sbug70277.php on line %d -bool(false) -Fatal error: Uncaught Exception: DateTimeZone::__construct(): Timezone must not contain null bytes in %sbug70277.php:%d -Stack trace: -#0 %sbug70277.php(%d): DateTimeZone->__construct('Europe/Zurich\x00F...') -#1 {main} - thrown in %sbug70277.php on line %d +try { + var_dump(timezone_open($timezone)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} + +try { + var_dump(new DateTimeZone($timezone)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} + +?> +--EXPECT-- +Timezone must not contain null bytes +Timezone must not contain null bytes diff --git a/ext/date/tests/date_default_timezone_get-4.phpt b/ext/date/tests/date_default_timezone_get-4.phpt index 6d1982bc13d1b..ff1d672dbe64b 100644 --- a/ext/date/tests/date_default_timezone_get-4.phpt +++ b/ext/date/tests/date_default_timezone_get-4.phpt @@ -4,8 +4,11 @@ date_default_timezone_get() function [4] date.timezone=Incorrect/Zone --FILE-- getMessage() . \PHP_EOL; +} ?> ---EXPECTF-- -Warning: date_default_timezone_get(): Invalid date.timezone value 'Incorrect/Zone', we selected the timezone 'UTC' for now. in %sdate_default_timezone_get-4.php on line %d -UTC +--EXPECT-- +Invalid date.timezone value 'Incorrect/Zone' diff --git a/ext/date/tests/date_interval_create_from_date_string_broken.phpt b/ext/date/tests/date_interval_create_from_date_string_broken.phpt index c065de0f8c1ce..7457a44893f09 100644 --- a/ext/date/tests/date_interval_create_from_date_string_broken.phpt +++ b/ext/date/tests/date_interval_create_from_date_string_broken.phpt @@ -2,9 +2,13 @@ Test date_interval_create_from_date_string() function : nonsense data --FILE-- getMessage() . \PHP_EOL; +} + ?> ---EXPECTF-- -Warning: date_interval_create_from_date_string(): Unknown or bad format (foobar) at position 0 (f): The timezone could not be found in the database in %sdate_interval_create_from_date_string_broken.php on line 2 -bool(false) +--EXPECT-- +Unknown or bad format (foobar) at position 0 (f): The timezone could not be found in the database diff --git a/ext/date/tests/date_interval_create_from_date_string_nullparam.phpt b/ext/date/tests/date_interval_create_from_date_string_nullparam.phpt index e03386ad3c4f4..429273c95e2f6 100644 --- a/ext/date/tests/date_interval_create_from_date_string_nullparam.phpt +++ b/ext/date/tests/date_interval_create_from_date_string_nullparam.phpt @@ -4,9 +4,13 @@ Test date_interval_create_from_date_string() function : null parameter Rodrigo Prado de Jesus --FILE-- getMessage() . \PHP_EOL; +} + ?> ---EXPECTF-- -Warning: date_interval_create_from_date_string(): Unknown or bad format () at position 0 ( ): Empty string in %sdate_interval_create_from_date_string_nullparam.php on line 2 -bool(false) +--EXPECT-- +Unknown or bad format () at position 0 ( ): Empty string diff --git a/ext/date/tests/ini_set_incorrect.phpt b/ext/date/tests/ini_set_incorrect.phpt index 1077333591087..34f4096de0f9c 100644 --- a/ext/date/tests/ini_set_incorrect.phpt +++ b/ext/date/tests/ini_set_incorrect.phpt @@ -3,8 +3,12 @@ Test invalid time zone passed to ini_set --FILE-- getMessage() . \PHP_EOL; +} ?> ---EXPECTF-- -Warning: ini_set(): Invalid date.timezone value 'Incorrect/Zone', we selected the timezone 'UTC' for now. in %sini_set_incorrect.php on line %d +--EXPECT-- +Invalid date.timezone value 'Incorrect/Zone' diff --git a/ext/date/tests/oo_001.phpt b/ext/date/tests/oo_001.phpt index 111364ec83362..d934a861b5a6e 100644 --- a/ext/date/tests/oo_001.phpt +++ b/ext/date/tests/oo_001.phpt @@ -24,7 +24,7 @@ try { try { new DateTime("1am todax"); -} catch (Exception $e) { +} catch (\Error $e) { echo $e->getMessage(),"\n"; } @@ -34,23 +34,21 @@ var_dump($t->getName()); try { $t = new _t; var_dump($t->getName()); -} catch (Error $e) { +} catch (\Error $e) { echo $e->getMessage(),"\n"; } try { new DateTimeZone("GottaFindThisOne"); -} catch (Exception $e) { +} catch (\Error $e) { echo $e->getMessage(),"\n"; } -echo "DONE\n"; ?> --EXPECTF-- string(19) "%d-%d-%d %d:%d:%d" The DateTime object has not been correctly initialized by its constructor -DateTime::__construct(): Failed to parse time string (1am todax) at position 4 (t): The timezone could not be found in the database +Failed to parse time string (1am todax) at position 4 (t): The timezone could not be found in the database string(3) "UTC" The DateTimeZone object has not been correctly initialized by its constructor -DateTimeZone::__construct(): Unknown or bad timezone (GottaFindThisOne) -DONE +Unknown or bad timezone (GottaFindThisOne) diff --git a/ext/intl/tests/calendar_fromDateTime_error.phpt b/ext/intl/tests/calendar_fromDateTime_error.phpt index 6fbaeb57f89a6..6f13b1086001f 100644 --- a/ext/intl/tests/calendar_fromDateTime_error.phpt +++ b/ext/intl/tests/calendar_fromDateTime_error.phpt @@ -12,8 +12,8 @@ date_default_timezone_set('Europe/Lisbon'); try { IntlCalendar::fromDateTime("foobar"); -} catch (Exception $e) { - echo "threw exception, OK"; +} catch (\Error $e) { + echo get_class($e) . ': ' . $e->getMessage() . \PHP_EOL; } class A extends DateTime { function __construct() {} @@ -27,7 +27,8 @@ var_dump(IntlCalendar::fromDateTime($date)); $date = new DateTime('2012-01-01 00:00:00 WEST'); var_dump(IntlCalendar::fromDateTime($date)); --EXPECTF-- -threw exception, OK +Error: Failed to parse time string (foobar) at position 0 (f): The timezone could not be found in the database + Warning: IntlCalendar::fromDateTime(): intlcal_from_date_time: DateTime object is unconstructed in %s on line %d NULL diff --git a/ext/intl/tests/calendar_toDateTime_error.phpt b/ext/intl/tests/calendar_toDateTime_error.phpt index ef799db61048f..56ccfbae84931 100644 --- a/ext/intl/tests/calendar_toDateTime_error.phpt +++ b/ext/intl/tests/calendar_toDateTime_error.phpt @@ -11,18 +11,12 @@ ini_set('date.timezone', 'Europe/Lisbon'); $cal = new IntlGregorianCalendar("Etc/Unknown"); try { -var_dump($cal->toDateTime()); -} catch (Exception $e) { -var_dump("exception: {$e->getMessage()}"); + var_dump($cal->toDateTime()); +} catch (\Error $e) { + echo get_class($e) . ': ' . $e->getMessage(); } -var_dump(intlcal_to_date_time(3)); --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)" +ValueError: Unknown or bad timezone (Etc/Unknown) -Fatal error: Uncaught TypeError: intlcal_to_date_time() expects parameter 1 to be IntlCalendar, int given in %s:%d -Stack trace: -#0 %s(%d): intlcal_to_date_time(3) -#1 {main} - thrown in %s on line %d diff --git a/ext/intl/tests/dateformat_invalid_timezone.phpt b/ext/intl/tests/dateformat_invalid_timezone.phpt index 5b54fa89bb301..525647227a142 100644 --- a/ext/intl/tests/dateformat_invalid_timezone.phpt +++ b/ext/intl/tests/dateformat_invalid_timezone.phpt @@ -11,8 +11,8 @@ extension_loaded('intl') || print 'skip'; try { new \IntlDateFormatter('en_US', \IntlDateFormatter::FULL, \IntlDateFormatter::FULL); echo "Wat?"; -} catch (\IntlException $e) { - echo $e->getMessage(); +} catch (\Error $e) { + echo get_class($e) . ': ' . $e->getMessage(); } --EXPECT-- -IntlDateFormatter::__construct(): Invalid date.timezone value 'Mars/Utopia_Planitia', we selected the timezone 'UTC' for now. +ValueError: Invalid date.timezone value 'Mars/Utopia_Planitia' diff --git a/ext/intl/tests/timezone_toDateTimeZone_error.phpt b/ext/intl/tests/timezone_toDateTimeZone_error.phpt index 9df2bbf70d3b1..89c7d11a8ab25 100644 --- a/ext/intl/tests/timezone_toDateTimeZone_error.phpt +++ b/ext/intl/tests/timezone_toDateTimeZone_error.phpt @@ -12,17 +12,10 @@ $tz = IntlTimeZone::createTimeZone('Etc/Unknown'); try { var_dump($tz->toDateTimeZone()); -} catch (Exception $e) { - var_dump($e->getMessage()); +} catch (\Error $e) { + echo get_class($e) . ': ' . $e->getMessage(); } -var_dump(intltz_to_date_time_zone(1)); --EXPECTF-- Warning: IntlTimeZone::toDateTimeZone(): intltz_to_date_time_zone: DateTimeZone constructor threw exception in %s on line %d -string(66) "DateTimeZone::__construct(): Unknown or bad timezone (Etc/Unknown)" - -Fatal error: Uncaught TypeError: intltz_to_date_time_zone() expects parameter 1 to be IntlTimeZone, int given in %s:%d -Stack trace: -#0 %s(%d): intltz_to_date_time_zone(1) -#1 {main} - thrown in %s on line %d +ValueError: Unknown or bad timezone (Etc/Unknown)