Skip to content

Commit 16757ca

Browse files
committed
Make notice in timezone_identifiers_list() into a ValueError
1 parent 6299627 commit 16757ca

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

ext/date/php_date.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4358,9 +4358,9 @@ PHP_FUNCTION(timezone_identifiers_list)
43584358

43594359
/* Extra validation */
43604360
if (what == PHP_DATE_TIMEZONE_PER_COUNTRY && option_len != 2) {
4361-
// Promoto to ValueError?
4362-
php_error_docref(NULL, E_NOTICE, "A two-letter ISO 3166-1 compatible country code is expected");
4363-
RETURN_FALSE;
4361+
zend_argument_value_error(2, "must be a two-letter ISO 3166-1 compatible country code "
4362+
"when argument #1 ($timezoneGroup) is DateTimeZone::PER_COUNTRY");
4363+
RETURN_THROWS();
43644364
}
43654365

43664366
tzdb = DATE_TIMEZONEDB;

ext/date/php_date.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function timezone_transitions_get(
8888

8989
function timezone_location_get(DateTimeZone $object): array|false {}
9090

91-
function timezone_identifiers_list(int $timezoneGroup = DateTimeZone::ALL, ?string $countryCode = null): array|false {}
91+
function timezone_identifiers_list(int $timezoneGroup = DateTimeZone::ALL, ?string $countryCode = null): array {}
9292

9393
function timezone_abbreviations_list(): array {}
9494

ext/date/php_date_arginfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: d334411c862c9140486ced1c7dffaebd8461a841 */
2+
* Stub hash: 88ffa20bdb76b268afd12d1499fa13173045567e */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_strtotime, 0, 1, MAY_BE_LONG|MAY_BE_FALSE)
55
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
184184
ZEND_ARG_OBJ_INFO(0, object, DateTimeZone, 0)
185185
ZEND_END_ARG_INFO()
186186

187-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_timezone_identifiers_list, 0, 0, MAY_BE_ARRAY|MAY_BE_FALSE)
187+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_timezone_identifiers_list, 0, 0, IS_ARRAY, 0)
188188
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, timezoneGroup, IS_LONG, 0, "DateTimeZone::ALL")
189189
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, countryCode, IS_STRING, 1, "null")
190190
ZEND_END_ARG_INFO()
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
--TEST--
2-
timezone_identifiers_list: Test that correct notice is given when timezone_identifiers_list is given 4096 as parameter
2+
timezone_identifiers_list: ValueError when timezoneGroup is DateTimeZone::PER_COUNTRY
33
--CREDITS--
44
Havard Eide <nucleuz@gmail.com>
55
#PHPTestFest2009 Norway 2009-06-09 \o/
66
--INI--
7-
error_reporting=E_ALL
87
date.timezone=UTC
98
--FILE--
109
<?php
11-
print_r(timezone_identifiers_list(4096));
10+
try {
11+
var_dump(timezone_identifiers_list(DateTimeZone::PER_COUNTRY));
12+
} catch (\ValueError $e) {
13+
echo $e->getMessage() . \PHP_EOL;
14+
}
15+
try {
16+
var_dump(timezone_identifiers_list(DateTimeZone::PER_COUNTRY, 'A'));
17+
} catch (\ValueError $e) {
18+
echo $e->getMessage() . \PHP_EOL;
19+
}
1220

1321
?>
1422
--EXPECTF--
15-
Notice: timezone_identifiers_list(): A two-letter ISO 3166-1 compatible country code is expected in %s on line %d
23+
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
24+
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

0 commit comments

Comments
 (0)