大网数据广告活动
PHP 语言与运行手册

The ResourceBundle class

· 52CE 我爱测

(PHP 5 >= 5.3.2, PHP 7, PHP 8, PECL intl >= 2.0.0)

The ResourceBundle class

(PHP 5 >= 5.3.2, PHP 7, PHP 8, PECL intl >= 2.0.0)

Introduction

Localized software products often require sets of data that are to be customized depending on current locale, e.g.: messages, labels, formatting patterns. ICU resource mechanism allows to define sets of resources that the application can load on locale basis, while accessing them in unified locale-independent fashion.

This class implements access to ICU resource data files. These files are binary data arrays which ICU uses to store the localized data.

ICU resource bundle can hold simple resources and complex resources. Complex resources are containers which can be either integer-indexed or string-indexed (just like PHP arrays). Simple resources can be of the following types: string, integer, binary data field or integer array.

ResourceBundle supports direct access to the data through array access pattern and iteration via foreach, as well as access via class methods. The result will be PHP value for simple resources and ResourceBundle object for complex ones. All resources are read-only.

Class synopsis

class ResourceBundle implements IteratorAggregate, Countable {
/* Methods */
public function __construct(?string $locale, ?string $bundle, bool $fallback = true)
public function count(): int
public static function create(?string $locale, ?string $bundle, bool $fallback = true): ?ResourceBundle
public function get(string|int $index, bool $fallback = true): ResourceBundle|array|string|int|null
public function getErrorCode(): int
public function getErrorMessage(): string
public static function getLocales(string $bundle): array|false
}

Changelog

Version Description
8.0.0 ResourceBundle implements IteratorAggregate now. Previously, Traversable was implemented instead.
7.4.0 ResourceBundle implements Countable now.

Table of Contents

来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
PHP Documentation Group
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。