From 68f47b6765d74f2ff4d55e1a6f2c41fb78b7e96a Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Fri, 22 May 2020 16:43:07 +0200 Subject: [PATCH 01/11] Add some ValueErrors to ext/date --- ext/date/php_date.c | 59 +++++++++++++++++++++++++----------- ext/date/php_date.stub.php | 4 +-- ext/date/php_date_arginfo.h | 8 ++--- ext/date/tests/005.phpt | 52 +++++++++++++++++++------------ ext/date/tests/bug70277.phpt | 24 ++++++++------- 5 files changed, 91 insertions(+), 56 deletions(-) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 841f280323e00..86e8e7357172b 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -550,7 +550,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. Please file a bug report as this should never happen"); } return tzi; } @@ -951,8 +951,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_argument_value_error(1, "must be one character"); + RETURN_THROWS(); } if (ts_is_null) { @@ -961,8 +961,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_argument_value_error(1, "must be a valid date format token"); + RETURN_THROWS(); } RETURN_LONG(ret); } @@ -1022,6 +1022,12 @@ PHP_FUNCTION(strtotime) Z_PARAM_LONG_OR_NULL(preset_ts, preset_ts_is_null) ZEND_PARSE_PARAMETERS_END(); + /* timelib_strtotime() expects the string to not be empty */ + if (ZSTR_LEN(times) == 0) { + /* TODO Add a Warning? */ + RETURN_FALSE; + } + tzi = get_timezone_info(); now = timelib_time_ctor(); @@ -1034,6 +1040,12 @@ PHP_FUNCTION(strtotime) DATE_TIMEZONEDB, php_date_parse_tzfile_wrapper); error1 = error->error_count; timelib_error_container_dtor(error); + if (error1) { + timelib_time_dtor(now); + timelib_time_dtor(t); + RETURN_FALSE; + } + timelib_fill_holes(t, now, TIMELIB_NO_CLONE); timelib_update_ts(t, tzi); ts = timelib_date_to_int(t, &error2); @@ -1041,11 +1053,13 @@ PHP_FUNCTION(strtotime) timelib_time_dtor(now); timelib_time_dtor(t); - if (error1 || error2) { + /* Seconds since epoch must fit in a zend_long */ + if (error2) { + /* TODO Add warning? */ RETURN_FALSE; - } else { - RETURN_LONG(ts); } + + RETURN_LONG(ts); } /* }}} */ @@ -1116,14 +1130,18 @@ PHPAPI void php_mktime(INTERNAL_FUNCTION_PARAMETERS, int gmt) /* Clean up and return */ ts = timelib_date_to_int(now, &error); - ts += adjust_seconds; - timelib_time_dtor(now); + /* Seconds since epoch must fit in a zend_long */ if (error) { + timelib_time_dtor(now); + /* TODO Add warning? */ RETURN_FALSE; - } else { - RETURN_LONG(ts); } + + ts += adjust_seconds; + timelib_time_dtor(now); + + RETURN_LONG(ts); } /* }}} */ @@ -1180,6 +1198,7 @@ PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gmt) ZEND_PARSE_PARAMETERS_END(); if (ZSTR_LEN(format) == 0) { + /* TODO Add a warning? */ RETURN_FALSE; } @@ -1224,7 +1243,7 @@ PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gmt) ta.tm_zone = offset->abbr; #endif } - + // TODO Cleanup as bug is not present anymore? (Need to update link as MS retired connect.microsoft.com) /* VS2012 crt has a bug where strftime crash with %z and %Z format when the initial buffer is too small. See http://connect.microsoft.com/VisualStudio/feedback/details/759720/vs2012-strftime-crash-with-z-formatting-code */ @@ -2781,7 +2800,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; } @@ -3319,11 +3338,14 @@ PHP_FUNCTION(date_timestamp_get) timelib_update_ts(dateobj->time, NULL); timestamp = timelib_date_to_int(dateobj->time, &error); + + /* Seconds since epoch must fit in a zend_long */ if (error) { + /* TODO Add warning? */ RETURN_FALSE; - } else { - RETVAL_LONG(timestamp); } + + RETURN_LONG(timestamp); } /* }}} */ @@ -3387,7 +3409,7 @@ PHP_FUNCTION(timezone_open) php_timezone_obj *tzobj; ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_STR(tz) + Z_PARAM_PATH_STR(tz) /* To prevent nul bytes */ ZEND_PARSE_PARAMETERS_END(); tzobj = Z_PHPTIMEZONE_P(php_date_instantiate(date_ce_timezone, return_value)); @@ -3406,7 +3428,7 @@ PHP_METHOD(DateTimeZone, __construct) zend_error_handling error_handling; ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_STR(tz) + Z_PARAM_PATH_STR(tz) /* To prevent nul bytes */ ZEND_PARSE_PARAMETERS_END(); zend_replace_error_handling(EH_THROW, NULL, &error_handling); @@ -4336,6 +4358,7 @@ PHP_FUNCTION(timezone_identifiers_list) /* Extra validation */ if (what == PHP_DATE_TIMEZONE_PER_COUNTRY && option_len != 2) { + // Promoto to ValueError? php_error_docref(NULL, E_NOTICE, "A two-letter ISO 3166-1 compatible country code is expected"); RETURN_FALSE; } diff --git a/ext/date/php_date.stub.php b/ext/date/php_date.stub.php index bb97cf5b86ca8..acd4684f5aa61 100644 --- a/ext/date/php_date.stub.php +++ b/ext/date/php_date.stub.php @@ -6,7 +6,7 @@ function strtotime(string $datetime, ?int $baseTimestamp = null): int|false {} function date(string $format, ?int $timestamp = null): string {} -function idate(string $format, ?int $timestamp = null): int|false {} +function idate(string $format, ?int $timestamp = null): int {} function gmdate(string $format, ?int $timestamp = null): string {} @@ -73,7 +73,7 @@ function date_isodate_set(DateTime $object, int $year, int $week, int $day = 1): function date_timestamp_set(DateTime $object, int $timestamp): DateTime {} -function date_timestamp_get(DateTimeInterface $object): int|false {} +function date_timestamp_get(DateTimeInterface $object): int {} function timezone_open(string $timezone): DateTimeZone|false {} diff --git a/ext/date/php_date_arginfo.h b/ext/date/php_date_arginfo.h index bc12d852bb905..2d8fc16ea2d05 100644 --- a/ext/date/php_date_arginfo.h +++ b/ext/date/php_date_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: fee95924adec03c89fdd677ec26bb6eea34d4b3c */ + * Stub hash: a1b54f5aa27f583fb84953c1aa3f5d901ceb9f9d */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_strtotime, 0, 1, MAY_BE_LONG|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, datetime, IS_STRING, 0) @@ -11,7 +11,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_date, 0, 1, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, timestamp, IS_LONG, 1, "null") 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_WITH_DEFAULT_VALUE(0, timestamp, IS_LONG, 1, "null") ZEND_END_ARG_INFO() @@ -151,9 +151,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_date_timestamp_set, 0, 2, DateTim ZEND_ARG_TYPE_INFO(0, timestamp, IS_LONG, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_date_timestamp_get, 0, 1, MAY_BE_LONG|MAY_BE_FALSE) - ZEND_ARG_OBJ_INFO(0, object, DateTimeInterface, 0) -ZEND_END_ARG_INFO() +#define arginfo_date_timestamp_get arginfo_date_offset_get ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_timezone_open, 0, 1, DateTimeZone, MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, timezone, IS_STRING, 0) diff --git a/ext/date/tests/005.phpt b/ext/date/tests/005.phpt index 23fff3b731ad2..361862902ff15 100644 --- a/ext/date/tests/005.phpt +++ b/ext/date/tests/005.phpt @@ -6,30 +6,42 @@ 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("'")); + +try { + var_dump(idate("[", $t)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + var_dump(idate("'")); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} echo "Done\n"; ?> ---EXPECTF-- -Warning: idate(): Unrecognized date format token. in %s on line %d -bool(false) - -Warning: idate(): idate format is one char in %s on line %d -bool(false) - -Warning: idate(): Unrecognized date format token. in %s on line %d -bool(false) +--EXPECT-- +idate(): Argument #1 ($format) must be a valid date format token +idate(): Argument #1 ($format) must be one character +idate(): Argument #1 ($format) must be a valid 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) +idate(): Argument #1 ($format) must be a valid date format token +idate(): Argument #1 ($format) must be a valid date format token Done diff --git a/ext/date/tests/bug70277.phpt b/ext/date/tests/bug70277.phpt index 648bd19c7771c..49df2be410379 100644 --- a/ext/date/tests/bug70277.phpt +++ b/ext/date/tests/bug70277.phpt @@ -3,15 +3,17 @@ Bug #70277 (new DateTimeZone($foo) is ignoring text after null byte) --FILE-- getMessage() . \PHP_EOL; +} +try { + var_dump(new DateTimeZone($timezone)); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} ?> ---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 +--EXPECT-- +timezone_open(): Argument #1 ($timezone) must not contain any null bytes +DateTimeZone::__construct(): Argument #1 ($timezone) must not contain any null bytes From 1e3509ba1aa947ecddb3f7b4cfb16d37885e01c7 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Thu, 10 Sep 2020 18:06:21 +0200 Subject: [PATCH 02/11] Fix null byte comment --- ext/date/php_date.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 86e8e7357172b..be52356369a71 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -3409,7 +3409,7 @@ PHP_FUNCTION(timezone_open) php_timezone_obj *tzobj; ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_PATH_STR(tz) /* To prevent nul bytes */ + Z_PARAM_PATH_STR(tz) /* To prevent null bytes */ ZEND_PARSE_PARAMETERS_END(); tzobj = Z_PHPTIMEZONE_P(php_date_instantiate(date_ce_timezone, return_value)); @@ -3428,7 +3428,7 @@ PHP_METHOD(DateTimeZone, __construct) zend_error_handling error_handling; ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_PATH_STR(tz) /* To prevent nul bytes */ + Z_PARAM_PATH_STR(tz) /* To prevent null bytes */ ZEND_PARSE_PARAMETERS_END(); zend_replace_error_handling(EH_THROW, NULL, &error_handling); From b6fea368e2f63b42bf7518c99b1aa6682a501c2b Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Thu, 10 Sep 2020 18:08:20 +0200 Subject: [PATCH 03/11] Fix stubs/arginfo --- ext/date/php_date.stub.php | 2 +- ext/date/php_date_arginfo.h | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/ext/date/php_date.stub.php b/ext/date/php_date.stub.php index acd4684f5aa61..94412323ba3f7 100644 --- a/ext/date/php_date.stub.php +++ b/ext/date/php_date.stub.php @@ -73,7 +73,7 @@ function date_isodate_set(DateTime $object, int $year, int $week, int $day = 1): function date_timestamp_set(DateTime $object, int $timestamp): DateTime {} -function date_timestamp_get(DateTimeInterface $object): int {} +function date_timestamp_get(DateTimeInterface $object): int|false {} function timezone_open(string $timezone): DateTimeZone|false {} diff --git a/ext/date/php_date_arginfo.h b/ext/date/php_date_arginfo.h index 2d8fc16ea2d05..c54a1ddd0365a 100644 --- a/ext/date/php_date_arginfo.h +++ b/ext/date/php_date_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: a1b54f5aa27f583fb84953c1aa3f5d901ceb9f9d */ + * Stub hash: d334411c862c9140486ced1c7dffaebd8461a841 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_strtotime, 0, 1, MAY_BE_LONG|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, datetime, IS_STRING, 0) @@ -151,7 +151,9 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_date_timestamp_set, 0, 2, DateTim ZEND_ARG_TYPE_INFO(0, timestamp, IS_LONG, 0) ZEND_END_ARG_INFO() -#define arginfo_date_timestamp_get arginfo_date_offset_get +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_date_timestamp_get, 0, 1, MAY_BE_LONG|MAY_BE_FALSE) + ZEND_ARG_OBJ_INFO(0, object, DateTimeInterface, 0) +ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_timezone_open, 0, 1, DateTimeZone, MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, timezone, IS_STRING, 0) From 6f8f866b22a50644035a7f95b1f5956cdb1d605b Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Thu, 10 Sep 2020 18:24:02 +0200 Subject: [PATCH 04/11] Make notice in timezone_identifiers_list() into a ValueError --- ext/date/php_date.c | 6 +++--- ext/date/php_date.stub.php | 2 +- ext/date/php_date_arginfo.h | 4 ++-- ...zone_identifiers_list_wrong_constructor.phpt | 17 +++++++++++++---- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index be52356369a71..6ddc06cb8bc4c 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -4358,9 +4358,9 @@ PHP_FUNCTION(timezone_identifiers_list) /* Extra validation */ if (what == PHP_DATE_TIMEZONE_PER_COUNTRY && option_len != 2) { - // Promoto to ValueError? - php_error_docref(NULL, E_NOTICE, "A two-letter ISO 3166-1 compatible country code is expected"); - RETURN_FALSE; + zend_argument_value_error(2, "must be a two-letter ISO 3166-1 compatible country code " + "when argument #1 ($timezoneGroup) is DateTimeZone::PER_COUNTRY"); + RETURN_THROWS(); } tzdb = DATE_TIMEZONEDB; diff --git a/ext/date/php_date.stub.php b/ext/date/php_date.stub.php index 94412323ba3f7..5aac396032c68 100644 --- a/ext/date/php_date.stub.php +++ b/ext/date/php_date.stub.php @@ -88,7 +88,7 @@ function timezone_transitions_get( function timezone_location_get(DateTimeZone $object): array|false {} -function timezone_identifiers_list(int $timezoneGroup = DateTimeZone::ALL, ?string $countryCode = null): array|false {} +function timezone_identifiers_list(int $timezoneGroup = DateTimeZone::ALL, ?string $countryCode = null): array {} function timezone_abbreviations_list(): array {} diff --git a/ext/date/php_date_arginfo.h b/ext/date/php_date_arginfo.h index c54a1ddd0365a..a73e92f53f561 100644 --- a/ext/date/php_date_arginfo.h +++ b/ext/date/php_date_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: d334411c862c9140486ced1c7dffaebd8461a841 */ + * Stub hash: 88ffa20bdb76b268afd12d1499fa13173045567e */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_strtotime, 0, 1, MAY_BE_LONG|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, datetime, IS_STRING, 0) @@ -184,7 +184,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_timezone_location_get, 0, 1, MAY ZEND_ARG_OBJ_INFO(0, object, DateTimeZone, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_timezone_identifiers_list, 0, 0, MAY_BE_ARRAY|MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_timezone_identifiers_list, 0, 0, IS_ARRAY, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, timezoneGroup, IS_LONG, 0, "DateTimeZone::ALL") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, countryCode, IS_STRING, 1, "null") ZEND_END_ARG_INFO() diff --git a/ext/date/tests/timezone_identifiers_list_wrong_constructor.phpt b/ext/date/tests/timezone_identifiers_list_wrong_constructor.phpt index 39c71ab1dbd27..4823027b551c0 100644 --- a/ext/date/tests/timezone_identifiers_list_wrong_constructor.phpt +++ b/ext/date/tests/timezone_identifiers_list_wrong_constructor.phpt @@ -1,15 +1,24 @@ --TEST-- -timezone_identifiers_list: Test that correct notice is given when timezone_identifiers_list is given 4096 as parameter +timezone_identifiers_list: ValueError when timezoneGroup is DateTimeZone::PER_COUNTRY --CREDITS-- Havard Eide #PHPTestFest2009 Norway 2009-06-09 \o/ --INI-- -error_reporting=E_ALL date.timezone=UTC --FILE-- getMessage() . \PHP_EOL; +} +try { + var_dump(timezone_identifiers_list(DateTimeZone::PER_COUNTRY, 'A')); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} ?> --EXPECTF-- -Notice: timezone_identifiers_list(): A two-letter ISO 3166-1 compatible country code is expected in %s on line %d +timezone_identifiers_list(): Argument #2 ($countryCode) must be a two-letter ISO 3166-1 compatible country code when argument #1 ($timezoneGroup) is DateTimeZone::PER_COUNTRY +timezone_identifiers_list(): Argument #2 ($countryCode) must be a two-letter ISO 3166-1 compatible country code when argument #1 ($timezoneGroup) is DateTimeZone::PER_COUNTRY From 48240d5c841ab277ec1082a68a99f7781a3a3714 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Thu, 10 Sep 2020 19:03:47 +0200 Subject: [PATCH 05/11] Add warnings for when Epoch doesn't fit in a PHP integer --- ext/date/php_date.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 6ddc06cb8bc4c..b23af5f4ed613 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -1009,7 +1009,7 @@ PHPAPI zend_long php_parse_date(const char *string, zend_long *now) PHP_FUNCTION(strtotime) { zend_string *times; - int error1, error2; + int error1, epoch_does_not_fit_in_zend_long; timelib_error_container *error; zend_long preset_ts, ts; zend_bool preset_ts_is_null = 1; @@ -1024,7 +1024,6 @@ PHP_FUNCTION(strtotime) /* timelib_strtotime() expects the string to not be empty */ if (ZSTR_LEN(times) == 0) { - /* TODO Add a Warning? */ RETURN_FALSE; } @@ -1048,14 +1047,14 @@ PHP_FUNCTION(strtotime) timelib_fill_holes(t, now, TIMELIB_NO_CLONE); timelib_update_ts(t, tzi); - ts = timelib_date_to_int(t, &error2); + ts = timelib_date_to_int(t, &epoch_does_not_fit_in_zend_long); timelib_time_dtor(now); timelib_time_dtor(t); /* Seconds since epoch must fit in a zend_long */ - if (error2) { - /* TODO Add warning? */ + if (epoch_does_not_fit_in_zend_long) { + php_error_docref(NULL, E_WARNING, "Epoch doesn't fit in a PHP integer"); RETURN_FALSE; } @@ -1071,7 +1070,7 @@ PHPAPI void php_mktime(INTERNAL_FUNCTION_PARAMETERS, int gmt) timelib_time *now; timelib_tzinfo *tzi = NULL; zend_long ts, adjust_seconds = 0; - int error; + int epoch_does_not_fit_in_zend_long; ZEND_PARSE_PARAMETERS_START(1, 6) Z_PARAM_LONG(hou) @@ -1129,12 +1128,12 @@ PHPAPI void php_mktime(INTERNAL_FUNCTION_PARAMETERS, int gmt) } /* Clean up and return */ - ts = timelib_date_to_int(now, &error); + ts = timelib_date_to_int(now, &epoch_does_not_fit_in_zend_long); /* Seconds since epoch must fit in a zend_long */ - if (error) { + if (epoch_does_not_fit_in_zend_long) { timelib_time_dtor(now); - /* TODO Add warning? */ + php_error_docref(NULL, E_WARNING, "Epoch doesn't fit in a PHP integer"); RETURN_FALSE; } @@ -1198,7 +1197,6 @@ PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gmt) ZEND_PARSE_PARAMETERS_END(); if (ZSTR_LEN(format) == 0) { - /* TODO Add a warning? */ RETURN_FALSE; } @@ -3328,7 +3326,7 @@ PHP_FUNCTION(date_timestamp_get) zval *object; php_date_obj *dateobj; zend_long timestamp; - int error; + int epoch_does_not_fit_in_zend_long; if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &object, date_ce_interface) == FAILURE) { RETURN_THROWS(); @@ -3337,11 +3335,11 @@ PHP_FUNCTION(date_timestamp_get) DATE_CHECK_INITIALIZED(dateobj->time, DateTime); timelib_update_ts(dateobj->time, NULL); - timestamp = timelib_date_to_int(dateobj->time, &error); + timestamp = timelib_date_to_int(dateobj->time, &epoch_does_not_fit_in_zend_long); /* Seconds since epoch must fit in a zend_long */ - if (error) { - /* TODO Add warning? */ + if (epoch_does_not_fit_in_zend_long) { + php_error_docref(NULL, E_WARNING, "Epoch doesn't fit in a PHP integer"); RETURN_FALSE; } From 2e24885eefad2a58306ec7cc1eb43fb6786bcf32 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Thu, 10 Sep 2020 19:15:09 +0200 Subject: [PATCH 06/11] Make epoch doesn't fit into PHP String a value error for date_timestamp_get() --- ext/date/php_date.c | 4 ++-- ext/date/php_date.stub.php | 6 +++--- ext/date/php_date_arginfo.h | 6 ++---- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index b23af5f4ed613..945a40e22a6f0 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -3339,8 +3339,8 @@ PHP_FUNCTION(date_timestamp_get) /* Seconds since epoch must fit in a zend_long */ if (epoch_does_not_fit_in_zend_long) { - php_error_docref(NULL, E_WARNING, "Epoch doesn't fit in a PHP integer"); - RETURN_FALSE; + zend_value_error("Epoch doesn't fit in a PHP integer"); + RETURN_THROWS(); } RETURN_LONG(timestamp); diff --git a/ext/date/php_date.stub.php b/ext/date/php_date.stub.php index 5aac396032c68..73a574e413af6 100644 --- a/ext/date/php_date.stub.php +++ b/ext/date/php_date.stub.php @@ -73,7 +73,7 @@ function date_isodate_set(DateTime $object, int $year, int $week, int $day = 1): function date_timestamp_set(DateTime $object, int $timestamp): DateTime {} -function date_timestamp_get(DateTimeInterface $object): int|false {} +function date_timestamp_get(DateTimeInterface $object): int {} function timezone_open(string $timezone): DateTimeZone|false {} @@ -230,7 +230,7 @@ public function setISODate(int $year, int $week, int $dayOfWeek = 1) {} public function setTimestamp(int $timestamp) {} /** - * @return int|false + * @return int * @alias date_timestamp_get */ public function getTimestamp() {} @@ -282,7 +282,7 @@ public function getTimezone() {} public function getOffset() {} /** - * @return int|false + * @return int * @alias date_timestamp_get */ public function getTimestamp() {} diff --git a/ext/date/php_date_arginfo.h b/ext/date/php_date_arginfo.h index a73e92f53f561..960fb650f2f29 100644 --- a/ext/date/php_date_arginfo.h +++ b/ext/date/php_date_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 88ffa20bdb76b268afd12d1499fa13173045567e */ + * Stub hash: eae561b0424a4837d35239b66be8c545d7ac2b04 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_strtotime, 0, 1, MAY_BE_LONG|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, datetime, IS_STRING, 0) @@ -151,9 +151,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_date_timestamp_set, 0, 2, DateTim ZEND_ARG_TYPE_INFO(0, timestamp, IS_LONG, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_date_timestamp_get, 0, 1, MAY_BE_LONG|MAY_BE_FALSE) - ZEND_ARG_OBJ_INFO(0, object, DateTimeInterface, 0) -ZEND_END_ARG_INFO() +#define arginfo_date_timestamp_get arginfo_date_offset_get ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_timezone_open, 0, 1, DateTimeZone, MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, timezone, IS_STRING, 0) From aa48d8e67a1e4d9655b1342e8b628f9425e5fb4d Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Thu, 10 Sep 2020 19:15:42 +0200 Subject: [PATCH 07/11] Drop todo comment because it's impossible to find the new link to said ticket --- ext/date/php_date.c | 1 - 1 file changed, 1 deletion(-) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 945a40e22a6f0..2aa7ddf78d79d 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -1241,7 +1241,6 @@ PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gmt) ta.tm_zone = offset->abbr; #endif } - // TODO Cleanup as bug is not present anymore? (Need to update link as MS retired connect.microsoft.com) /* VS2012 crt has a bug where strftime crash with %z and %Z format when the initial buffer is too small. See http://connect.microsoft.com/VisualStudio/feedback/details/759720/vs2012-strftime-crash-with-z-formatting-code */ From 4f9cae2e1481353724094e92f169637158feb9e5 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Mon, 14 Sep 2020 19:17:58 +0200 Subject: [PATCH 08/11] Drop comment and rename error1 var --- ext/date/php_date.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 2aa7ddf78d79d..a3cf14e3a37e9 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -1009,7 +1009,7 @@ PHPAPI zend_long php_parse_date(const char *string, zend_long *now) PHP_FUNCTION(strtotime) { zend_string *times; - int error1, epoch_does_not_fit_in_zend_long; + int parse_error, epoch_does_not_fit_in_zend_long; timelib_error_container *error; zend_long preset_ts, ts; zend_bool preset_ts_is_null = 1; @@ -1037,9 +1037,9 @@ PHP_FUNCTION(strtotime) t = timelib_strtotime(ZSTR_VAL(times), ZSTR_LEN(times), &error, DATE_TIMEZONEDB, php_date_parse_tzfile_wrapper); - error1 = error->error_count; + parse_error = error->error_count; timelib_error_container_dtor(error); - if (error1) { + if (parse_error) { timelib_time_dtor(now); timelib_time_dtor(t); RETURN_FALSE; @@ -1052,7 +1052,6 @@ PHP_FUNCTION(strtotime) timelib_time_dtor(now); timelib_time_dtor(t); - /* Seconds since epoch must fit in a zend_long */ if (epoch_does_not_fit_in_zend_long) { php_error_docref(NULL, E_WARNING, "Epoch doesn't fit in a PHP integer"); RETURN_FALSE; @@ -1130,7 +1129,6 @@ PHPAPI void php_mktime(INTERNAL_FUNCTION_PARAMETERS, int gmt) /* Clean up and return */ ts = timelib_date_to_int(now, &epoch_does_not_fit_in_zend_long); - /* Seconds since epoch must fit in a zend_long */ if (epoch_does_not_fit_in_zend_long) { timelib_time_dtor(now); php_error_docref(NULL, E_WARNING, "Epoch doesn't fit in a PHP integer"); @@ -3336,7 +3334,6 @@ PHP_FUNCTION(date_timestamp_get) timestamp = timelib_date_to_int(dateobj->time, &epoch_does_not_fit_in_zend_long); - /* Seconds since epoch must fit in a zend_long */ if (epoch_does_not_fit_in_zend_long) { zend_value_error("Epoch doesn't fit in a PHP integer"); RETURN_THROWS(); From 9362d5a81287308030be53fce0a8db73fc331fe6 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Mon, 14 Sep 2020 19:29:18 +0200 Subject: [PATCH 09/11] Revert idate() changes --- ext/date/php_date.c | 8 +++--- ext/date/php_date.stub.php | 2 +- ext/date/php_date_arginfo.h | 4 +-- ext/date/tests/005.phpt | 53 ++++++++++++++----------------------- 4 files changed, 27 insertions(+), 40 deletions(-) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index a3cf14e3a37e9..d44dfa4d77c7b 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -951,8 +951,8 @@ PHP_FUNCTION(idate) ZEND_PARSE_PARAMETERS_END(); if (ZSTR_LEN(format) != 1) { - zend_argument_value_error(1, "must be one character"); - RETURN_THROWS(); + php_error_docref(NULL, E_WARNING, "idate format is one char"); + RETURN_FALSE; } if (ts_is_null) { @@ -961,8 +961,8 @@ PHP_FUNCTION(idate) ret = php_idate(ZSTR_VAL(format)[0], ts, 0); if (ret == -1) { - zend_argument_value_error(1, "must be a valid date format token"); - RETURN_THROWS(); + php_error_docref(NULL, E_WARNING, "Unrecognized date format token"); + RETURN_FALSE; } RETURN_LONG(ret); } diff --git a/ext/date/php_date.stub.php b/ext/date/php_date.stub.php index 73a574e413af6..8a1e86a3a0547 100644 --- a/ext/date/php_date.stub.php +++ b/ext/date/php_date.stub.php @@ -6,7 +6,7 @@ function strtotime(string $datetime, ?int $baseTimestamp = null): int|false {} function date(string $format, ?int $timestamp = null): string {} -function idate(string $format, ?int $timestamp = null): int {} +function idate(string $format, ?int $timestamp = null): int|false {} function gmdate(string $format, ?int $timestamp = null): string {} diff --git a/ext/date/php_date_arginfo.h b/ext/date/php_date_arginfo.h index 960fb650f2f29..19ee60f5c1c99 100644 --- a/ext/date/php_date_arginfo.h +++ b/ext/date/php_date_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: eae561b0424a4837d35239b66be8c545d7ac2b04 */ + * Stub hash: cb1532309655d85eb2644cdcfbf23063dfa1ddaf */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_strtotime, 0, 1, MAY_BE_LONG|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, datetime, IS_STRING, 0) @@ -11,7 +11,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_date, 0, 1, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, timestamp, IS_LONG, 1, "null") ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_idate, 0, 1, IS_LONG, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_idate, 0, 1, MAY_BE_LONG|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, format, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, timestamp, IS_LONG, 1, "null") ZEND_END_ARG_INFO() diff --git a/ext/date/tests/005.phpt b/ext/date/tests/005.phpt index 361862902ff15..4bd743ea006db 100644 --- a/ext/date/tests/005.phpt +++ b/ext/date/tests/005.phpt @@ -6,42 +6,29 @@ date_default_timezone_set('UTC'); $t = mktime(0,0,0, 6, 27, 2006); -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(1,1)); +var_dump(idate("")); +var_dump(idate(0)); var_dump(idate("B", $t)); - -try { - var_dump(idate("[", $t)); -} catch (\ValueError $e) { - echo $e->getMessage() . \PHP_EOL; -} -try { - var_dump(idate("'")); -} catch (\ValueError $e) { - echo $e->getMessage() . \PHP_EOL; -} +var_dump(idate("[", $t)); +var_dump(idate("'")); echo "Done\n"; ?> ---EXPECT-- -idate(): Argument #1 ($format) must be a valid date format token -idate(): Argument #1 ($format) must be one character -idate(): Argument #1 ($format) must be a valid date format token +--EXPECTF-- +Warning: idate(): Unrecognized date format token in %s on line %d +bool(false) + +Warning: idate(): idate format is one char in %s on line %d +bool(false) + +Warning: idate(): Unrecognized date format token in %s on line %d +bool(false) int(41) -idate(): Argument #1 ($format) must be a valid date format token -idate(): Argument #1 ($format) must be a valid date format token + +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 From a72f3cbb45a04d8a7784d39e13ffa5631dea9fea Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Tue, 15 Sep 2020 03:33:39 +0200 Subject: [PATCH 10/11] Fix OpCache --- ext/opcache/Optimizer/zend_func_info.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/opcache/Optimizer/zend_func_info.c b/ext/opcache/Optimizer/zend_func_info.c index 04d3b50ecde3f..edbc068dda2ec 100644 --- a/ext/opcache/Optimizer/zend_func_info.c +++ b/ext/opcache/Optimizer/zend_func_info.c @@ -434,7 +434,7 @@ static const func_info_t func_infos[] = { F1("timezone_name_from_abbr", MAY_BE_FALSE | MAY_BE_STRING), F1("timezone_transitions_get", MAY_BE_FALSE | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_ANY), F1("timezone_location_get", MAY_BE_FALSE | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_STRING | MAY_BE_ARRAY_OF_DOUBLE | MAY_BE_ARRAY_OF_STRING), - F1("timezone_identifiers_list", MAY_BE_FALSE | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_LONG | MAY_BE_ARRAY_OF_STRING), + F1("timezone_identifiers_list", MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_LONG | MAY_BE_ARRAY_OF_STRING), F1("timezone_abbreviations_list", MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_STRING | MAY_BE_ARRAY_OF_ARRAY), F1("timezone_version_get", MAY_BE_STRING), F1("date_interval_create_from_date_string", MAY_BE_FALSE | MAY_BE_OBJECT), From 52593f5285bdaeffe23e4f19427cc9b3835cf543 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Tue, 15 Sep 2020 16:17:56 +0200 Subject: [PATCH 11/11] Fix 32bit tests --- ext/date/tests/bug41523.phpt | 4 +- ext/date/tests/bug52062.phpt | 16 +++-- ext/date/tests/gmdate_variation12.phpt | 34 ++++++----- ext/date/tests/gmdate_variation12_64bits.phpt | 44 ++++++++++++++ ext/date/tests/gmmktime_variation9.phpt | 50 ++++++++++------ .../tests/gmmktime_variation9_64bits.phpt | 58 +++++++++++++++++++ ext/date/tests/mktime-3.phpt | 2 +- ext/date/tests/strtotime-mysql.phpt | 4 +- ext/date/tests/strtotime3.phpt | 4 +- 9 files changed, 177 insertions(+), 39 deletions(-) create mode 100644 ext/date/tests/gmdate_variation12_64bits.phpt create mode 100644 ext/date/tests/gmmktime_variation9_64bits.phpt diff --git a/ext/date/tests/bug41523.phpt b/ext/date/tests/bug41523.phpt index 6df2006d57e66..2f0e3b1084818 100644 --- a/ext/date/tests/bug41523.phpt +++ b/ext/date/tests/bug41523.phpt @@ -12,7 +12,7 @@ var_dump( $dt = new DateTime('0000-00-00 00:00:00') ); echo $dt->format( DateTime::ISO8601 ), "\n"; ?> ---EXPECT-- +--EXPECTF-- array(12) { ["year"]=> int(0) @@ -43,6 +43,8 @@ array(12) { ["is_localtime"]=> bool(false) } + +Warning: strtotime(): Epoch doesn't fit in a PHP integer in %s on line %d bool(false) object(DateTime)#1 (3) { ["date"]=> diff --git a/ext/date/tests/bug52062.phpt b/ext/date/tests/bug52062.phpt index 1196168e19f21..f967773b1cc3c 100644 --- a/ext/date/tests/bug52062.phpt +++ b/ext/date/tests/bug52062.phpt @@ -10,7 +10,11 @@ date.timezone=UTC format('Y-m-d H:i:s U')); -var_dump($d->getTimestamp()); +try { + var_dump($d->getTimestamp()); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} var_dump($d->format('U')); try { @@ -19,16 +23,20 @@ try { echo $e->getMessage(), "\n"; } var_dump($d->format('Y-m-d H:i:s U')); -var_dump($d->getTimestamp()); +try { + var_dump($d->getTimestamp()); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} $i = new DateInterval('PT100000000000S'); var_dump($i->format('%s')); ?> --EXPECT-- string(32) "5138-11-16 09:46:40 100000000000" -bool(false) +Epoch doesn't fit in a PHP integer string(12) "100000000000" DateTime::setTimestamp(): Argument #1 ($timestamp) must be of type int, float given string(32) "5138-11-16 09:46:40 100000000000" -bool(false) +Epoch doesn't fit in a PHP integer string(10) "1215752192" diff --git a/ext/date/tests/gmdate_variation12.phpt b/ext/date/tests/gmdate_variation12.phpt index 1f74dc14c159e..dab866967aea1 100644 --- a/ext/date/tests/gmdate_variation12.phpt +++ b/ext/date/tests/gmdate_variation12.phpt @@ -1,5 +1,9 @@ --TEST-- -Test gmdate() function : usage variation - Valid and invalid range of timestamp. +Test gmdate() function : usage variation - Valid and invalid range of timestamp 32 bits. +--SKIPIF-- + --FILE-- ---EXPECTREGEX-- -\*\*\* Testing gmdate\(\) : usage variation \*\*\* +--EXPECTF-- +*** Testing gmdate() : usage variation *** + +-- Testing gmdate() function with minimum range of timestamp -- +string(24) "1901-12-13T20:45:54+0000" + +-- Testing gmdate() function with less than the range of timestamp -- --- Testing gmdate\(\) function with minimum range of timestamp -- -string\(24\) "1901-12-13T20:45:54\+0000" +Warning: mktime(): Epoch doesn't fit in a PHP integer in %s on line %d +string(24) "1970-01-01T00:00:00+0000" --- Testing gmdate\(\) function with less than the range of timestamp -- -string\(24\) "(1970-01-01T00:00:00\+0000|1901-12-13T20:45:50\+0000)" +-- Testing gmdate() function with maximum range of timestamp -- +string(24) "2038-01-19T03:14:07+0000" --- Testing gmdate\(\) function with maximum range of timestamp -- -string\(24\) "2038-01-19T03:14:07\+0000" +-- Testing gmdate() function with greater than the range of timestamp -- --- Testing gmdate\(\) function with greater than the range of timestamp -- -string\(24\) "(1970-01-01T00:00:00\+0000|2038-01-19T03:14:10\+0000)" +Warning: mktime(): Epoch doesn't fit in a PHP integer in %s on line %d +string(24) "1970-01-01T00:00:00+0000" diff --git a/ext/date/tests/gmdate_variation12_64bits.phpt b/ext/date/tests/gmdate_variation12_64bits.phpt new file mode 100644 index 0000000000000..5f3c87da09676 --- /dev/null +++ b/ext/date/tests/gmdate_variation12_64bits.phpt @@ -0,0 +1,44 @@ +--TEST-- +Test gmdate() function : usage variation - Valid and invalid range of timestamp 64 bits. +--SKIPIF-- + +--FILE-- + +--EXPECT-- +*** Testing gmdate() : usage variation *** + +-- Testing gmdate() function with minimum range of timestamp -- +string(24) "1901-12-13T20:45:54+0000" + +-- Testing gmdate() function with less than the range of timestamp -- +string(24) "1901-12-13T20:45:50+0000" + +-- Testing gmdate() function with maximum range of timestamp -- +string(24) "2038-01-19T03:14:07+0000" + +-- Testing gmdate() function with greater than the range of timestamp -- +string(24) "2038-01-19T03:14:10+0000" diff --git a/ext/date/tests/gmmktime_variation9.phpt b/ext/date/tests/gmmktime_variation9.phpt index c972e8c9c79a7..dea8e93fab674 100644 --- a/ext/date/tests/gmmktime_variation9.phpt +++ b/ext/date/tests/gmmktime_variation9.phpt @@ -1,5 +1,9 @@ --TEST-- -Test gmmktime() function : usage variation - Passing positive and negative float values to arguments. +Test gmmktime() function : usage variation - Passing positive and negative float values to arguments 32 bits. +--SKIPIF-- + --FILE-- $value) { var_dump( gmmktime($hour, $min, $sec, $mon, $value, $value) ); } ?> ---EXPECTREGEX-- -\*\*\* Testing gmmktime\(\) : usage variation \*\*\* +--EXPECTF-- +*** Testing gmmktime() : usage variation *** --float 123456-- -int\(1662595688\) -int\(1225589768\) -int\(1218306336\) -(bool|int)\((false|325855037288)\) -(bool|int)\((false|3844412784488)\) +int(1662595688) +int(1225589768) +int(1218306336) + +Warning: gmmktime(): Epoch doesn't fit in a PHP integer in %s on line %d +bool(false) + +Warning: gmmktime(): Epoch doesn't fit in a PHP integer in %s on line %d +bool(false) --float -123456-- -int\(773712488\) -int\(1210775048\) -int\(1218059424\) -(bool|int)\((false|-323460834712)\) -(bool|int)\((false|-3968710530712)\) +int(773712488) +int(1210775048) +int(1218059424) + +Warning: gmmktime(): Epoch doesn't fit in a PHP integer in %s on line %d +bool(false) + +Warning: gmmktime(): Epoch doesn't fit in a PHP integer in %s on line %d +bool(false) --float -10.5-- -int\(1218118088\) -int\(1218181808\) -int\(1218182870\) -int\(1170922088\) -(bool|int)\((false|-62465356312)\) +int(1218118088) +int(1218181808) +int(1218182870) +int(1170922088) + +Warning: gmmktime(): Epoch doesn't fit in a PHP integer in %s on line %d +bool(false) diff --git a/ext/date/tests/gmmktime_variation9_64bits.phpt b/ext/date/tests/gmmktime_variation9_64bits.phpt new file mode 100644 index 0000000000000..9c7e8dcc76c0b --- /dev/null +++ b/ext/date/tests/gmmktime_variation9_64bits.phpt @@ -0,0 +1,58 @@ +--TEST-- +Test gmmktime() function : usage variation - Passing positive and negative float values to arguments 64 bits. +--SKIPIF-- + +--FILE-- + 123456, + 'float -123456' => -123456, + 'float -10.5' => -10.5, +); + +// loop through each element of the array for min +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( gmmktime($value, $min, $sec, $mon, $day, $year) ); + var_dump( gmmktime($hour, $value, $sec, $mon, $day, $year) ); + var_dump( gmmktime($hour, $min, $value, $mon, $day, $year) ); + var_dump( gmmktime($hour, $min, $sec, $value, $day, $year) ); + var_dump( gmmktime($hour, $min, $sec, $mon, $value, $value) ); +} +?> +--EXPECT-- + *** Testing gmmktime() : usage variation *** + +--float 123456-- +int(1662595688) +int(1225589768) +int(1218306336) +int(325855037288) +int(3844412784488) + +--float -123456-- +int(773712488) +int(1210775048) +int(1218059424) +int(-323460834712) +int(-3968710530712) + +--float -10.5-- +int(1218118088) +int(1218181808) +int(1218182870) +int(1170922088) +int(-62465356312) diff --git a/ext/date/tests/mktime-3.phpt b/ext/date/tests/mktime-3.phpt index b054efd076ef9..2aacdee5aab2e 100644 --- a/ext/date/tests/mktime-3.phpt +++ b/ext/date/tests/mktime-3.phpt @@ -14,7 +14,7 @@ foreach ($tzs as $tz) { date_default_timezone_set($tz); foreach ($years as $year) { printf("Y: %4d - ", $year); - $ret = mktime(1, 1, 1, 1, 1, $year); + $ret = @mktime(1, 1, 1, 1, 1, $year); if ($ret == FALSE) { echo "out of range\n"; } else { diff --git a/ext/date/tests/strtotime-mysql.phpt b/ext/date/tests/strtotime-mysql.phpt index c9502e1d3e179..c51f63f1323ba 100644 --- a/ext/date/tests/strtotime-mysql.phpt +++ b/ext/date/tests/strtotime-mysql.phpt @@ -21,7 +21,9 @@ foreach($d as $date) { } } ?> ---EXPECT-- +--EXPECTF-- string(31) "Fri, 23 May 1997 09:15:28 +0000" string(31) "Sun, 31 Dec 2000 18:58:59 +0000" + +Warning: strtotime(): Epoch doesn't fit in a PHP integer in %s on line %d bool(false) diff --git a/ext/date/tests/strtotime3.phpt b/ext/date/tests/strtotime3.phpt index f01af27a4378e..763b77a07da97 100644 --- a/ext/date/tests/strtotime3.phpt +++ b/ext/date/tests/strtotime3.phpt @@ -44,7 +44,7 @@ foreach ($strs as $str) { } ?> ---EXPECT-- +--EXPECTF-- bool(false) bool(false) string(31) "Thu, 15 Jun 2006 00:00:00 +0100" @@ -53,6 +53,8 @@ bool(false) string(31) "Fri, 16 Jun 2006 23:49:12 +0100" bool(false) string(31) "Fri, 16 Jun 2006 02:22:00 +0100" + +Warning: strtotime(): Epoch doesn't fit in a PHP integer in %s on line %d bool(false) string(31) "Fri, 16 Jun 2006 02:22:33 +0100" bool(false)