Skip to content

Intl: Fix compile issues with ICU versions lower than 67 #18868

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions ext/intl/listformatter/listformatter.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@
*/
final class IntlListFormatter {

#if U_ICU_VERSION_MAJOR_NUM >= 67
/** @cvalue ULISTFMT_TYPE_AND */
public const int TYPE_AND = UNKNOWN;
#else
/** @cvalue INTL_LISTFORMATTER_FALLBACK_TYPE_AND */
public const int TYPE_AND = UNKNOWN;
#endif

#if U_ICU_VERSION_MAJOR_NUM >= 67
/** @cvalue ULISTFMT_TYPE_OR */
Expand All @@ -19,8 +24,13 @@ final class IntlListFormatter {
public const int TYPE_UNITS = UNKNOWN;
#endif

#if U_ICU_VERSION_MAJOR_NUM >= 67
/** @cvalue ULISTFMT_WIDTH_WIDE */
public const int WIDTH_WIDE = UNKNOWN;
#else
/** @cvalue INTL_LISTFORMATTER_FALLBACK_WIDTH_WIDE */
public const int WIDTH_WIDE = UNKNOWN;
#endif

#if U_ICU_VERSION_MAJOR_NUM >= 67
/** @cvalue ULISTFMT_WIDTH_SHORT */
Expand Down
22 changes: 21 additions & 1 deletion ext/intl/listformatter/listformatter_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions ext/intl/listformatter/listformatter_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#include "php.h"
#include "php_intl.h"
#include <unicode/ulistformatter.h>
#include "listformatter_arginfo.h"
#include "listformatter_class.h"
#include "listformatter_arginfo.h"
Copy link
Member

@devnexen devnexen Jun 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks fine, did you need that change though ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, that's needed because the stub contains references to the fallbacks. listformatter_arginfo.h needs to be after.

Otherwise it would fail with

php-src/ext/intl/listformatter/listformatter_arginfo.h:50:35: error: use of undeclared identifier 'INTL_LISTFORMATTER_FALLBACK_TYPE_AND'

#include "intl_convert.h"

static zend_object_handlers listformatter_handlers;
Expand Down Expand Up @@ -53,8 +53,13 @@ PHP_METHOD(IntlListFormatter, __construct)
ListFormatter_object *obj = Z_INTL_LISTFORMATTER_P(ZEND_THIS);
char* locale;
size_t locale_len = 0;
zend_long type = ULISTFMT_TYPE_AND;
zend_long width = ULISTFMT_WIDTH_WIDE;
#if U_ICU_VERSION_MAJOR_NUM >= 67
zend_long type = ULISTFMT_TYPE_AND;
zend_long width = ULISTFMT_WIDTH_WIDE;
#else
zend_long type = INTL_LISTFORMATTER_FALLBACK_TYPE_AND;
zend_long width = INTL_LISTFORMATTER_FALLBACK_WIDTH_WIDE;
#endif
ZEND_PARSE_PARAMETERS_START(1, 3)
Z_PARAM_STRING(locale, locale_len)
Z_PARAM_OPTIONAL
Expand Down Expand Up @@ -90,12 +95,12 @@ PHP_METHOD(IntlListFormatter, __construct)

LISTFORMATTER_OBJECT(obj) = ulistfmt_openForType(locale, type, width, &status);
#else
if (type != ULISTFMT_TYPE_AND) {
if (type != INTL_LISTFORMATTER_FALLBACK_TYPE_AND) {
zend_argument_value_error(2, "contains an unsupported type. ICU 66 and below only support IntlListFormatter::TYPE_AND");
RETURN_THROWS();
}

if (width != ULISTFMT_WIDTH_WIDE) {
if (width != INTL_LISTFORMATTER_FALLBACK_WIDTH_WIDE) {
zend_argument_value_error(3, "contains an unsupported width. ICU 66 and below only support IntlListFormatter::WIDTH_WIDE");
RETURN_THROWS();
}
Expand Down
3 changes: 3 additions & 0 deletions ext/intl/listformatter/listformatter_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,7 @@ static inline ListFormatter_object *php_intl_listformatter_fetch_object(zend_obj
void listformatter_register_class( void );
extern zend_class_entry *ListFormatter_ce_ptr;

#define INTL_LISTFORMATTER_FALLBACK_TYPE_AND 0
#define INTL_LISTFORMATTER_FALLBACK_WIDTH_WIDE 0

#endif // LISTFORMATTER_CLASS_H