Permalink
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...
cataphract committed May 24, 2012
1 parent 0e12a77 commit 92039fed22cd68405589cf6df3af58b9beaddb16
Showing with 50 additions and 7 deletions.
  1. +4 −0 NEWS
  2. +5 −0 UPGRADING
  3. +15 −7 ext/intl/resourcebundle/resourcebundle_class.c
  4. +26 −0 ext/intl/tests/resourcebundle_null_mandatory_args.phpt
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
@@ -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
===========================
@@ -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();
}
}
@@ -0,0 +1,26 @@
+--TEST--
+IntlCalendar::setTime() basic test

This comment has been minimized.

Show comment Hide comment
@smalyshev

smalyshev Jul 30, 2012

Contributor

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

@smalyshev

smalyshev Jul 30, 2012

Contributor

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

This comment has been minimized.

Show comment Hide comment
@cataphract

cataphract Jul 30, 2012

Contributor

Fixed that in 86ca788.

@cataphract

cataphract Jul 30, 2012

Contributor

Fixed that in 86ca788.

+--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--

This comment has been minimized.

Show comment Hide comment
@smalyshev

smalyshev Jul 30, 2012

Contributor

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

@smalyshev

smalyshev Jul 30, 2012

Contributor

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

This comment has been minimized.

Show comment Hide comment
@cataphract

cataphract Jul 30, 2012

Contributor

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.

@cataphract

cataphract Jul 30, 2012

Contributor

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.

+string(14) "h:mm:ss a zzzz"
+string(12) "H:mm:ss zzzz"
+==DONE==

0 comments on commit 92039fe

Please sign in to comment.