Skip to content

Add Locale::getDisplayKeyword() and Locale::getDisplayKeywordValue()#22264

Merged
LamentXU123 merged 17 commits into
php:masterfrom
LamentXU123:implement-RFC-intl
Jun 30, 2026
Merged

Add Locale::getDisplayKeyword() and Locale::getDisplayKeywordValue()#22264
LamentXU123 merged 17 commits into
php:masterfrom
LamentXU123:implement-RFC-intl

Conversation

@LamentXU123

Copy link
Copy Markdown
Member

RFC: https://wiki.php.net/rfc/getdisplaykeyword_and_getdisplaykeywordvalue
No need to review until the voting process ends.

@LamentXU123

LamentXU123 commented Jun 20, 2026

Copy link
Copy Markdown
Member Author

Given the voting status of this RFC (17 agree; 0 disagree; 1 Abstain, ends in 6/23 22:00 UTC) It is very likely to be accepted. Thus, I am opening this PR to be ready for review.

@LamentXU123 LamentXU123 marked this pull request as ready for review June 20, 2026 05:42
Comment thread ext/intl/locale/locale.stub.php Outdated
@LamentXU123

Copy link
Copy Markdown
Member Author

The RFC is now accepted (18 yes 0 no 2 abstain)

@LamentXU123 LamentXU123 requested a review from kocsismate June 25, 2026 05:34
Comment thread ext/intl/php_intl.stub.php
@LamentXU123 LamentXU123 requested a review from devnexen June 29, 2026 09:38
Comment thread ext/intl/php_intl.stub.php
@LamentXU123 LamentXU123 requested a review from TimWolla June 29, 2026 16:46
@devnexen

Copy link
Copy Markdown
Member

I had another look, code wise it s good. the test coverage could be improved, e.g. ICU display values are hardcoded without version being guarded.

@TimWolla TimWolla left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can't comment on the implementation itself or the tests, I abstained from the RFC because I didn't understand it.

Z_PARAM_PATH_OR_NULL(disp_loc_name, disp_loc_name_len)
ZEND_PARSE_PARAMETERS_END();

if (loc_name_len > ULOC_FULLNAME_CAPACITY) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: loc_name is bounded but keyword_name is not, in either branch. Unlike the locale-name overflow (bug 67397), uloc_getDisplayKeyword{,Value} grows the output buffer in the loop and echoes unknown keywords back, so I do not think an overlong keyword can crash. Noting it for symmetry; fine to leave as-is.

Comment thread ext/intl/tests/locale_get_display_keyword.phpt Outdated
@LamentXU123

Copy link
Copy Markdown
Member Author

I had another look, code wise it s good. the test coverage could be improved, e.g. ICU display values are hardcoded without version being guarded.

Now I change it to only verifies that the returned values are non-empty strings, and that the explicit(default) display locale paths agree

I am merging this as the alpha 1 release is around the corner and it's good to get this in for public testing, since the implementation has been reviewed several times and is good enough code wise. We can adjust tests in the future (ideally I want to write new tests in bulk in the future because the test coverage of the intl extension is bad overall (82.97%))

@devnexen

Copy link
Copy Markdown
Member

I would have preferred if regexes, at least, were used in the tests instead.

ut_run();
?>
--EXPECTREGEX--
string\([1-9][0-9]*\) "[^"\n]+"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I meant ; there is probably a safe subset of characters to expect within a value ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I see. "[A-Za-z]+( [A-Za-z]+)*" should be safer but it could only test the spaces 🤔

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

not quite what I had in mind, e.g. previously was hardcoded "Gregorian Calendar", it might be safe to assume "Gregorian" token is going to be a safe assumption

@devnexen devnexen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm if CI is green

@LamentXU123 LamentXU123 merged commit 0c1d809 into php:master Jun 30, 2026
1 of 2 checks passed
@LamentXU123

Copy link
Copy Markdown
Member Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants