]> granicus.if.org Git - php/commitdiff
Produce a better exception message when IntlDateFormatter constructor fails.
authorSara Golemon <pollita@php.net>
Sun, 25 Jun 2017 21:44:59 +0000 (17:44 -0400)
committerSara Golemon <pollita@php.net>
Sun, 25 Jun 2017 21:44:59 +0000 (17:44 -0400)
ext/intl/dateformat/dateformat_create.cpp
ext/intl/tests/dateformat_invalid_timezone.phpt [new file with mode: 0644]

index 00a5cc593c8a8690f00ef23c67da582cd6e38836..e060711ce6950ef47d23783ff573d2c7d6cc8965 100644 (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);
diff --git a/ext/intl/tests/dateformat_invalid_timezone.phpt b/ext/intl/tests/dateformat_invalid_timezone.phpt
new file mode 100644 (file)
index 0000000..5b54fa8
--- /dev/null
@@ -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.