Produce a better exception message when IntlDateFormatter constructor fails.

This commit is contained in:
Sara Golemon 2017-06-25 17:44:59 -04:00
parent e5741da85c
commit ecaf408d30
No known key found for this signature in database
GPG key ID: DBDB397470D12172
2 changed files with 19 additions and 1 deletions

View file

@ -216,7 +216,7 @@ U_CFUNC PHP_METHOD( IntlDateFormatter, __construct )
return_value = getThis();
if (datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1) == FAILURE) {
if (!EG(exception)) {
zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0);
zend_throw_exception(IntlException_ce_ptr, ZSTR_VAL(intl_error_get_message(NULL)), intl_error_get_code(NULL));
}
}
zend_restore_error_handling(&error_handling);

View file

@ -0,0 +1,18 @@
--TEST--
IntlDateFormat constructor failure
--INI--
date.timezone=Mars/Utopia_Planitia
--SKIPIF--
<?php
extension_loaded('intl') || print 'skip';
--FILE--
<?php
try {
new \IntlDateFormatter('en_US', \IntlDateFormatter::FULL, \IntlDateFormatter::FULL);
echo "Wat?";
} catch (\IntlException $e) {
echo $e->getMessage();
}
--EXPECT--
IntlDateFormatter::__construct(): Invalid date.timezone value 'Mars/Utopia_Planitia', we selected the timezone 'UTC' for now.