Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Changed ResourceBundle constructor behavior

null is now accepted for two first (mandatory arguments).

Passing null as the package name causes NULL to be passed to ICU  and
the default ICU data to be loaded.

Passing null as the locale name causes the default locale to be used.
  • Loading branch information...
commit 92039fed22cd68405589cf6df3af58b9beaddb16 1 parent 0e12a77
@cataphract cataphract authored
View
4 NEWS
@@ -62,6 +62,10 @@ PHP NEWS
. Fixed bug #61839 (Unable to cross-compile PHP with --enable-fpm). (fat)
. Fixed bug #61026 (FPM pools can listen on the same address). (fat)
+- Intl
+ . ResourceBundle constructor now accepts NULL for the first two arguments.
+ (Gustavo)
+
- Libxml:
. Fixed bug #61617 (Libxml tests failed(ht is already destroyed)).
(Laruence)
View
5 UPGRADING
@@ -341,6 +341,8 @@ PHP 5.4 UPGRADE NOTES
- Since 5.4.4, "php://fd" stream syntax is available only in CLI build.
+- Since 5.4.5, resourcebundle_create() accepts null for the first two arguments.
+
==============================
5. Changes to existing classes
==============================
@@ -373,6 +375,9 @@ PHP 5.4 UPGRADE NOTES
- FilesystemIterator, GlobIterator and (Recursive)DirectoryIterator now use
the default stream context.
+- Since 5.4.5, the constructor of ResourceBundle accepts NULL for the first two
+ arguments.
+
===========================
7. Deprecated Functionality
===========================
View
22 ext/intl/resourcebundle/resourcebundle_class.c
@@ -91,7 +91,7 @@ static void resourcebundle_ctor(INTERNAL_FUNCTION_PARAMETERS)
intl_error_reset( NULL TSRMLS_CC );
- if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "ss|b",
+ if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "s!s!|b",
&locale, &locale_len, &bundlename, &bundlename_len, &fallback ) == FAILURE )
{
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
@@ -101,6 +101,10 @@ static void resourcebundle_ctor(INTERNAL_FUNCTION_PARAMETERS)
}
INTL_CHECK_LOCALE_LEN_OBJ(locale_len, return_value);
+
+ if (locale == NULL) {
+ locale = intl_locale_get_default(TSRMLS_C);
+ }
if (fallback) {
rb->me = ures_open(bundlename, locale, &INTL_DATA_ERROR_CODE(rb));
@@ -110,13 +114,17 @@ static void resourcebundle_ctor(INTERNAL_FUNCTION_PARAMETERS)
INTL_CTOR_CHECK_STATUS(rb, "resourcebundle_ctor: Cannot load libICU resource bundle");
- if (!fallback && (INTL_DATA_ERROR_CODE(rb) == U_USING_FALLBACK_WARNING || INTL_DATA_ERROR_CODE(rb) == U_USING_DEFAULT_WARNING)) {
- intl_errors_set_code( NULL, INTL_DATA_ERROR_CODE(rb) TSRMLS_CC );
- spprintf( &pbuf, 0, "resourcebundle_ctor: Cannot load libICU resource '%s' without fallback from %s to %s",
- bundlename, locale, ures_getLocaleByType( rb->me, ULOC_ACTUAL_LOCALE, &INTL_DATA_ERROR_CODE(rb)) );
- intl_errors_set_custom_msg( INTL_DATA_ERROR_P(rb), pbuf, 1 TSRMLS_CC );
+ if (!fallback && (INTL_DATA_ERROR_CODE(rb) == U_USING_FALLBACK_WARNING ||
+ INTL_DATA_ERROR_CODE(rb) == U_USING_DEFAULT_WARNING)) {
+ intl_errors_set_code(NULL, INTL_DATA_ERROR_CODE(rb) TSRMLS_CC);
+ spprintf(&pbuf, 0, "resourcebundle_ctor: Cannot load libICU resource "
+ "'%s' without fallback from %s to %s",
+ bundlename ? bundlename : "(default data)", locale,
+ ures_getLocaleByType(
+ rb->me, ULOC_ACTUAL_LOCALE, &INTL_DATA_ERROR_CODE(rb)));
+ intl_errors_set_custom_msg(INTL_DATA_ERROR_P(rb), pbuf, 1 TSRMLS_CC);
efree(pbuf);
- zval_dtor( return_value );
+ zval_dtor(return_value);
RETURN_NULL();
}
}
View
26 ext/intl/tests/resourcebundle_null_mandatory_args.phpt
@@ -0,0 +1,26 @@
+--TEST--
+IntlCalendar::setTime() basic test
@smalyshev Owner

Is this the correct name for the test? Seems to have nothing to do with IntlCalendar...

Fixed that in 86ca788.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+--INI--
+date.timezone=Atlantic/Azores
+--SKIPIF--
+<?php
+if (!extension_loaded('intl'))
+ die('skip intl extension not enabled');
+--FILE--
+<?php
+ini_set("intl.error_level", E_WARNING);
+
+$r = new ResourceBundle('en_US', NULL);
+$c = $r->get('calendar')->get('gregorian')->get('DateTimePatterns')->get(0);
+var_dump($c);
+
+ini_set('intl.default_locale', 'pt_PT');
+$r = new ResourceBundle(NULL, NULL);
+$c = $r->get('calendar')->get('gregorian')->get('DateTimePatterns')->get(0);
+var_dump($c);
+?>
+==DONE==
+--EXPECT--
@smalyshev Owner

This fails for me (ICU 4.2.1) - produces Warning: ResourceBundle::get(): Cannot load resource element 'DateTimePatterns'.

It fails with ICU 4.4 too (only the pt_PT parts works, but in any case the pattern returned is different). I have no idea why. Even going back in ICU's history, the only difference I can find (in the relatively short time I dedicated to this) between what PHP does in this case and what ICU does to retrieve the patterns is that ICU calls ures_getByKeyWithFallback instead of ures_getByKey. I don't know the ICU ResourceBundle API or implementation very well, so it would take me quite a lot of effort to get to the bottom of this. I'll have this test be ICU 4.8+, since I originally tested this on that version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+string(14) "h:mm:ss a zzzz"
+string(12) "H:mm:ss zzzz"
+==DONE==
Please sign in to comment.
Something went wrong with that request. Please try again.