php / php/php-src

Intl::composeLocale does not consider subtags

Open
#20,393 2 comments 0 reactions 1 assignee View on GitHub

@devnexen is already working on this.

Since Nov 5, 2025.

Extension: intl Feature Status: Verified
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

The following code:

<?php

$first = 'en_US@timezone=Europe/Amsterdam';
$second = 'nl_NL';

var_dump(\Locale::parseLocale($first));
var_dump(\Locale::getKeywords($first));
var_dump(\Locale::parseLocale($second));
var_dump(\Locale::getKeywords($second));

$merged = [
    ...\Locale::parseLocale($first),
    ...\Locale::getKeywords($first) ?? [],
    ...\Locale::parseLocale($second),
    ...\Locale::getKeywords($second) ?? [],
];

var_dump($merged);

var_dump(\Locale::composeLocale($merged));

$newSynax = 'en_US-u-tz-nlams';

var_dump(\Locale::parseLocale($newSynax));
var_dump(\Locale::getKeywords($newSynax));

Resulted in this output:

array(2) {
  ["language"]=>
  string(2) "en"
  ["region"]=>
  string(2) "US"
}
array(1) {
  ["timezone"]=>
  string(16) "Europe/Amsterdam"
}
array(2) {
  ["language"]=>
  string(2) "nl"
  ["region"]=>
  string(2) "NL"
}
NULL
array(3) {
  ["language"]=>
  string(2) "nl"
  ["region"]=>
  string(2) "NL"
  ["timezone"]=>
  string(16) "Europe/Amsterdam"
}
string(5) "nl_NL"
array(2) {
  ["language"]=>
  string(2) "en"
  ["region"]=>
  string(2) "US"
}
NULL

But I expected this output instead:

array(2) {
  ["language"]=>
  string(2) "en"
  ["region"]=>
  string(2) "US"
}
array(1) {
  ["timezone"]=>
  string(16) "Europe/Amsterdam"
}
array(2) {
  ["language"]=>
  string(2) "nl"
  ["region"]=>
  string(2) "NL"
}
NULL
array(3) {
  ["language"]=>
  string(2) "nl"
  ["region"]=>
  string(2) "NL"
  ["timezone"]=>
  string(16) "Europe/Amsterdam"
}
string(5) "nl_NL@timezone=Europe/Amsterdam"
array(2) {
  ["language"]=>
  string(2) "en"
  ["region"]=>
  string(2) "US"
}
array(1) {
  ["timezone"]=>
  string(16) "Europe/Amsterdam"
}

The reasoning behind this, as the example shows, is that I try to activate a new language and region while maintaining the other subtags.

PHP Version
PHP 8.2-8.5 and master
Operating System

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.