Skip to content

Commit ecaf408

Browse files
committed
Produce a better exception message when IntlDateFormatter constructor fails.
1 parent e5741da commit ecaf408

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

ext/intl/dateformat/dateformat_create.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ U_CFUNC PHP_METHOD( IntlDateFormatter, __construct )
216216
return_value = getThis();
217217
if (datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1) == FAILURE) {
218218
if (!EG(exception)) {
219-
zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
219+
zend_throw_exception(IntlException_ce_ptr, ZSTR_VAL(intl_error_get_message(NULL)), intl_error_get_code(NULL));
220220
}
221221
}
222222
zend_restore_error_handling(&error_handling);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
IntlDateFormat constructor failure
3+
--INI--
4+
date.timezone=Mars/Utopia_Planitia
5+
--SKIPIF--
6+
<?php
7+
extension_loaded('intl') || print 'skip';
8+
--FILE--
9+
<?php
10+
11+
try {
12+
new \IntlDateFormatter('en_US', \IntlDateFormatter::FULL, \IntlDateFormatter::FULL);
13+
echo "Wat?";
14+
} catch (\IntlException $e) {
15+
echo $e->getMessage();
16+
}
17+
--EXPECT--
18+
IntlDateFormatter::__construct(): Invalid date.timezone value 'Mars/Utopia_Planitia', we selected the timezone 'UTC' for now.

0 commit comments

Comments
 (0)