Skip to content

Replace non-runnable intl_get_error_message() example with a copy-paste runnable one #5558

@masakielastic

Description

@masakielastic

Affected page

https://www.php.net/manual/en/function.intl-get-error-message.php

Current issue

The current example for intl_get_error_message() uses Collator::getAvailableLocales():

<?php
if (Collator::getAvailableLocales() === false) {
    show_error(intl_get_error_message());
}
?>

However, PHP's Collator class does not provide a getAvailableLocales() method.

As a result, the example is not copy-paste runnable and may confuse readers who expect examples in the manual to use existing PHP APIs.

The example is also not ideal for explaining what intl_get_error_message() adds compared with intl_error_name(). For example, using collator_create('en_RU') may produce the same symbolic value for both functions:

Error code: -128
Error name: U_USING_FALLBACK_WARNING
Error message: U_USING_FALLBACK_WARNING

In this case, the difference between the symbolic ICU error name and the descriptive intl error message is not clear.

Suggested improvement

Replace the current example with one that intentionally triggers an intl error using an existing PHP API, and shows both intl_error_name() and intl_get_error_message().

Suggested example:

<?php

$bundle = resourcebundle_create('en_US', __DIR__ . '/does-not-exist', false);

if ($bundle === null) {
    $errorCode = intl_get_error_code();

    printf("Error name: %s\n", intl_error_name($errorCode));
    printf("Error message: %s\n", intl_get_error_message());
}

Example output:

Error name: U_MISSING_RESOURCE_ERROR
Error message: resourcebundle_create(): Cannot load libICU resource bundle: U_MISSING_RESOURCE_ERROR

This example has several advantages:

  • It uses existing PHP intl APIs.
  • It is copy-paste runnable.
  • It clearly demonstrates an intl failure.
  • It shows the difference between intl_error_name() and intl_get_error_message().
  • It demonstrates that intl_get_error_message() can include context about the most recent intl API call, not only the symbolic ICU error name.

Additional context (optional)

This may become more relevant with PHP 8.5, because several grapheme_* functions now accept a $locale parameter. Invalid locale handling can be diagnosed through intl_get_error_code() and intl_get_error_message().

So it would be useful for the intl_get_error_message() page to provide a reliable, runnable example of how to inspect intl error details.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions