Skip to content

Intl: Add a new IntlNumberRangeFormatter class #19232

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions ext/intl/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ if test "$PHP_INTL" != "no"; then
dateformat/datepatterngenerator_class.cpp \
dateformat/datepatterngenerator_methods.cpp \
msgformat/msgformat_helpers.cpp \
rangeformatter/rangeformatter_class.cpp \
timezone/timezone_class.cpp \
timezone/timezone_methods.cpp \
calendar/calendar_class.cpp \
Expand Down Expand Up @@ -123,6 +124,7 @@ if test "$PHP_INTL" != "no"; then
$ext_builddir/listformatter
$ext_builddir/msgformat
$ext_builddir/normalizer
$ext_builddir/rangeformatter
$ext_builddir/resourcebundle
$ext_builddir/spoofchecker
$ext_builddir/timezone
Expand Down
3 changes: 3 additions & 0 deletions ext/intl/config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ if (PHP_INTL != "no") {
normalizer_class.c \
normalizer_normalize.c \
", "intl");
ADD_SOURCES(configure_module_dirname + "/rangeformatter", "\
rangeformatter_class.cpp \
", "intl");
ADD_SOURCES(configure_module_dirname + "/dateformat", "\
dateformat.c \
dateformat_class.c \
Expand Down
4 changes: 4 additions & 0 deletions ext/intl/php_intl.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "locale/locale_class.h"

#include "listformatter/listformatter_class.h"
#include "rangeformatter/rangeformatter_class.h"

#include "dateformat/dateformat.h"
#include "dateformat/dateformat_class.h"
Expand Down Expand Up @@ -161,6 +162,9 @@ PHP_MINIT_FUNCTION( intl )
/* Register 'ListFormatter' PHP class */
listformatter_register_class( );

/* Register 'NumberRangeFormatter' PHP class */
rangeformatter_register_class( );

/* Register 'Normalizer' PHP class */
normalizer_register_Normalizer_class( );

Expand Down
61 changes: 61 additions & 0 deletions ext/intl/rangeformatter/rangeformatter.stub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

/** @generate-class-entries */

/**
* @not-serializable
* @strict-properties
*/
final class IntlNumberRangeFormatter {
#if U_ICU_VERSION_MAJOR_NUM >= 63
/** @cvalue UNUM_RANGE_COLLAPSE_AUTO */
public const int COLLAPSE_AUTO = UNKNOWN;

/** @cvalue UNUM_RANGE_COLLAPSE_NONE */
public const int COLLAPSE_NONE = UNKNOWN;

/** @cvalue UNUM_RANGE_COLLAPSE_UNIT */
public const int COLLAPSE_UNIT = UNKNOWN;

/** @cvalue UNUM_RANGE_COLLAPSE_ALL */
public const int COLLAPSE_ALL = UNKNOWN;

/** @cvalue UNUM_IDENTITY_FALLBACK_SINGLE_VALUE */
public const int IDENTITY_FALLBACK_SINGLE_VALUE = UNKNOWN;

/** @cvalue UNUM_IDENTITY_FALLBACK_APPROXIMATELY_OR_SINGLE_VALUE */
public const int IDENTITY_FALLBACK_APPROXIMATELY_OR_SINGLE_VALUE = UNKNOWN;

/** @cvalue UNUM_IDENTITY_FALLBACK_APPROXIMATELY */
public const int IDENTITY_FALLBACK_APPROXIMATELY = UNKNOWN;

/** @cvalue UNUM_IDENTITY_FALLBACK_RANGE */
public const int IDENTITY_FALLBACK_RANGE = UNKNOWN;
#else
public const int COLLAPSE_AUTO = 0;

public const int COLLAPSE_NONE = 1;

public const int COLLAPSE_UNIT = 2;

public const int COLLAPSE_ALL = 3;

public const int IDENTITY_FALLBACK_SINGLE_VALUE = 0;

public const int IDENTITY_FALLBACK_APPROXIMATELY_OR_SINGLE_VALUE = 1;

public const int IDENTITY_FALLBACK_APPROXIMATELY = 2;

public const int IDENTITY_FALLBACK_RANGE = 3;
#endif

private function __construct() {}

public static function createFromSkeleton(string $skeleton, string $locale, int $collapse, int $identityFallback): IntlNumberRangeFormatter {}
Copy link
Member

@kocsismate kocsismate Jul 25, 2025

Choose a reason for hiding this comment

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

I hope I won't upset you too much, but I think these changes will need an RFC, because any API changes involve a lot of bikeshedding lately.

For example, we have started to use enums more often (see my https://wiki.php.net/rfc/url_parsing_api RFC), so I think this practice could be continued in your case too.

Copy link
Member

Choose a reason for hiding this comment

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

Hm, I see that you have recently added the ListFormatter class in #18519 that also has some enum-like constants. It probably also makes sense to stay consistent with the current convention of intl (class constants), so I don't insist on my above suggestion.

Copy link
Member

Choose a reason for hiding this comment

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

If we decide that we should employ nicer features in intl, we should do a thorough review of not only the constants ,but other mechanisms (like error handling) as well. And then we can make one compelling holistic RFC (if we would desire to do so ;) ).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, I see that you have recently added the ListFormatter class in #18519 that also has some enum-like constants. It probably also makes sense to stay consistent with the current convention of intl (class constants), so I don't insist on my above suggestion.

Yeah, that was my reasoning. Since that one didn't need an RFC, I thought this one also won't need it.

If we decide that we should employ nicer features in intl, we should do a thorough review of not only the constants ,but other mechanisms (like error handling) as well. And then we can make one compelling holistic RFC (if we would desire to do so ;) ).

Sounds fair. I think for now the API I'm proposing is ok. I do agree introducing the new NumberFormatter will require an RFC.


public function format(float|int $start, float|int $end): string {}

public function getErrorCode(): int {}

public function getErrorMessage(): string {}
}
148 changes: 148 additions & 0 deletions ext/intl/rangeformatter/rangeformatter_arginfo.h

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

Loading
Loading