# PHP Readable documentation (v8.6.x)

> Canonical: https://pharaonic.dev/packages/php/readable/8.6.x  
> Version: v8.6.x (latest release 8.6.0, 2026-12-01)  
> Install: composer require pharaonic/php-readable  
> Requires: PHP 8.6  
> Repository: https://github.com/Pharaonic/php-readable  
> All versions: https://pharaonic.dev/packages/php/readable/8.6.x.md https://pharaonic.dev/packages/php/readable/8.5.x.md https://pharaonic.dev/packages/php/readable/8.4.x.md https://pharaonic.dev/packages/php/readable/8.3.x.md https://pharaonic.dev/packages/php/readable/8.2.x.md https://pharaonic.dev/packages/php/readable/8.1.x.md https://pharaonic.dev/packages/php/readable/8.0.x.md

:::badges
- PHP Package {color=blue}
- v8.6.0 {color=green}
- MIT License {color=purple}
:::

# PHP Readable

Human-friendly formatting for plain PHP. Readable turns raw values into text people can read at a glance: `1250000` becomes `1.3M`, `1536` bytes become `1.5 KiB`, `3661` seconds become `1 hour 1 minute 1 second`. Each kind of value has its own small class of static methods, the output is the same on every machine, and Intl locales are there when you need them.

:::features
### Numbers
Grouped, compact, percentage, ordinal and spelled-out numbers: 1,234,567, 1.2M, 75%, 21st and twenty-one.

### Byte Sizes
1500 bytes become 1.5 KB, 1536 bytes become 1.5 KiB, and "10 MB" parses back to 10000000.

### Money
1234.5 USD becomes USD 1,234.50, with the ISO 4217 minor units of every currency.

### Durations
3661 seconds become 1 hour 1 minute 1 second, and two dates give a calendar-exact difference.

### Strings & Arrays
Initials for avatars (Moamen Eltouny becomes ME), plus null, nested and list checks for arrays.

### Optional Locales
Pass a locale such as de_DE to format with Intl, or leave it out for a deterministic English formatter.
:::

:::info Quick Tip
Every class lives in the `Pharaonic\Readable` namespace, so one grouped import covers them all: `use Pharaonic\Readable\{Arr, Bytes, Duration, Money, Number, Str};`
:::

## Installation

Install the package with Composer. There is nothing to register, publish or configure.

### Requirements

- PHP 8.6.x (each `8.x` release line targets the matching PHP version)
- `ext-mbstring`
- `ext-intl` *(optional)*: only needed when you pass a `$locale`

### Composer Installation

```bash title="Terminal" no-line-numbers
composer require pharaonic/php-readable
```

Composer autoloads the `Pharaonic\Readable` namespace. The package ships no global functions.

:::success Installation Complete
You're all set! Try `Number::compact(1250000)`, which returns `1.3M`.
:::

## Basic Usage

Import the class for the kind of value you have and call a static method. Every formatter returns a `string`.

```php title="example.php"
use Pharaonic\Readable\{Arr, Bytes, Duration, Money, Number, Str};

Number::format(1234567.891, 2);   // "1,234,567.89"
Number::compact(1250000);         // "1.3M"
Bytes::format(1500);              // "1.5 KB"
Money::format(1234.5, 'USD');     // "USD 1,234.50"
Duration::format(3661);           // "1 hour 1 minute 1 second"
Str::initials('Moamen Eltouny');  // "ME"
Arr::isList([10, 20, 30]);        // true
```

### Named arguments

Optional arguments come after the value, so named arguments keep calls readable when you skip some of them:

```php title="example.php"
Number::format(70.50, 2, trimZeros: true);  // "70.5"
Bytes::format(1536, binary: true);          // "1.5 KiB"
Duration::format(90061, parts: 2);          // "1 day 1 hour"
Money::format(1234.5, 'USD', decimals: 0);  // "USD 1,235"
```

### Rules shared by every formatter

- **Rounding** is half away from zero, like `number_format()`: `Number::format(2.5)` is `"3"` and `Number::format(-2.5)` is `"-3"`.
- **No negative zero.** A negative value that rounds to zero prints as zero: `Number::format(-0.001, 2)` is `"0.00"`.
- **Invalid input throws `InvalidArgumentException`:** `INF`, `NAN`, decimals below 0 or above 100, a malformed currency code, an unparsable size, or a date string PHP cannot read.
- **No state.** There is no global configuration; everything a call needs is in its arguments.

## Locales & Intl

`Number::format()`, `percentage()`, `ordinal()`, `spell()`, `Bytes::format()` and `Money::format()` accept an optional `?string $locale` as their last argument.

### Without a locale (default)

Readable uses its own English formatter: `,` for thousands, `.` for decimals, English suffixes and words. The output is identical on every machine, with or without the intl extension.

```php title="example.php"
Number::format(1234567.891, 2);  // "1,234,567.89"
Number::ordinal(22);             // "22nd"
Number::spell(7721);             // "seven thousand seven hundred twenty-one"
```

### With a locale

Readable formats through Intl's `NumberFormatter`, still rounding half away from zero:

```php title="example.php"
Number::format(1234567.891, 2, locale: 'de_DE');   // "1.234.567,89"
Number::percentage(0.756, 1, 'de_DE');             // "75,6 %"
Number::ordinal(21, 'fr');                         // "21e"
Number::spell(21, 'fr');                           // "vingt-et-un"
Money::format(1234.5, 'USD', locale: 'en_US');     // "$1,234.50"
Bytes::format(1500, locale: 'de_DE');              // "1,5 KB"
```

For Arabic locales, `Number::spell()` attaches the conjunction "و" to the following word: `Number::spell(21, 'ar')` returns `"واحد وعشرون"`.

:::warning Intl is required for locales
Passing a locale without `ext-intl` throws `Pharaonic\Readable\Exceptions\MissingIntlExtension` (a `RuntimeException`) instead of silently printing English. A locale that Intl itself rejects throws `InvalidArgumentException`.
:::

:::info Spaces in Intl output
Intl separates some parts with a no-break space (U+00A0) or a narrow no-break space (U+202F), for example in `"1.234,50 €"`. Keep that in mind when you compare strings in tests.
:::

`Number::compact()`, `Money::compact()`, `Duration` and `Str` have no locale argument: their output is always English.

## Numbers

`Pharaonic\Readable\Number` formats integers and floats.

### Grouped numbers

`Number::format()` groups thousands and fixes the number of decimals (`0` by default):

```php title="example.php"
Number::format(1234567);           // "1,234,567"
Number::format(60708.547, 2);      // "60,708.55"
Number::format(70, 2);             // "70.00"
Number::format(-1234567);          // "-1,234,567"
Number::format(PHP_INT_MAX);       // "9,223,372,036,854,775,807"
```

With `trimZeros: true`, trailing fraction zeros are dropped:

```php title="example.php"
Number::format(70.50, 2, trimZeros: true);  // "70.5"
Number::format(70.00, 2, trimZeros: true);  // "70"
Number::format(70.07, 2, trimZeros: true);  // "70.07"
```

:::info Custom separators
For other separators without a locale, use PHP's own `number_format($number, 2, ',', '.')`.
:::

### Compact numbers

`Number::compact()` shortens a number with a `K`, `M`, `B` or `T` suffix, keeping at most `$decimals` fraction digits (`1` by default) and dropping trailing zeros:

```php title="example.php"
Number::compact(999);         // "999"
Number::compact(77700);       // "77.7K"
Number::compact(77700, 0);    // "78K"
Number::compact(77370, 2);    // "77.37K"
Number::compact(1000000);     // "1M"
Number::compact(3400000000);  // "3.4B"
Number::compact(-1500);       // "-1.5K"
```

When rounding reaches the next unit, the next unit is used: `Number::compact(999950)` is `"1M"`, not `"1,000K"`. Values past 999 trillion keep the `T` suffix: `Number::compact(1.5e15)` is `"1,500T"`.

### Percentages

`Number::percentage()` takes a **ratio**, where `1` is 100%:

```php title="example.php"
Number::percentage(0.75);        // "75%"
Number::percentage(1);           // "100%"
Number::percentage(0.1234, 1);   // "12.3%"
Number::percentage(-0.1);        // "-10%"
```

:::warning Ratio, not percent
`Number::percentage(75)` is `"7,500%"`. Divide by 100 first if your value is already a percentage.
:::

### Ordinals

```php title="example.php"
Number::ordinal(1);     // "1st"
Number::ordinal(22);    // "22nd"
Number::ordinal(113);   // "113th"
Number::ordinal(1001);  // "1,001st"
Number::ordinal(-11);   // "-11th"
```

### Numbers in words

`Number::spell()` follows ICU's English rules: no "and", hyphenated tens, and fraction digits read one by one. It covers every `int` and floats up to the decillions.

```php title="example.php"
Number::spell(21);       // "twenty-one"
Number::spell(101);      // "one hundred one"
Number::spell(7721);     // "seven thousand seven hundred twenty-one"
Number::spell(-5);       // "minus five"
Number::spell(3.14);     // "three point one four"
Number::spell(1000001);  // "one million one"
```

Floats are read from their shortest exact representation, so `Number::spell(0.1)` is `"zero point one"`.

## Byte Sizes

`Pharaonic\Readable\Bytes` formats and parses byte counts.

### Units

Two conventions, never mixed:

| Convention | Base | Units | How |
| --- | --- | --- | --- |
| SI decimal | 1000 | `B`, `KB`, `MB`, `GB`, `TB`, `PB`, `EB`, `ZB`, `YB` | default |
| IEC binary | 1024 | `B`, `KiB`, `MiB`, `GiB`, `TiB`, `PiB`, `EiB`, `ZiB`, `YiB` | `binary: true` |

### Formatting

`Bytes::format()` keeps at most `$decimals` fraction digits (`2` by default) and drops trailing zeros:

```php title="example.php"
Bytes::format(0);                    // "0 B"
Bytes::format(1000);                 // "1 KB"
Bytes::format(1024);                 // "1.02 KB"
Bytes::format(1500);                 // "1.5 KB"
Bytes::format(1536, binary: true);   // "1.5 KiB"
Bytes::format(1073741824, binary: true); // "1 GiB"
Bytes::format(1234, 1);              // "1.2 KB"
Bytes::format(-2048, binary: true);  // "-2 KiB"
```

Rounding can move a value to the next unit: `Bytes::format(999999)` is `"1 MB"`, not `"1000 KB"`.

### Parsing

`Bytes::parse()` turns a readable size back into an `int`. Units are case-insensitive, `KB` is decimal and `KiB` is binary, the same as `format()`:

```php title="example.php"
Bytes::parse('512');        // 512
Bytes::parse('512 bytes');  // 512
Bytes::parse('10 MB');      // 10000000
Bytes::parse('10mb');       // 10000000
Bytes::parse('1.5 KiB');    // 1536
Bytes::parse('2 GiB');      // 2147483648
```

Whole numbers are multiplied exactly; fractional bytes are rounded half away from zero.

:::warning Rejected input
`Bytes::parse()` throws `InvalidArgumentException` for anything it can't read unambiguously: a prefix without `B` (`"10 K"`), bits (`"10 Mbit"`), thousands separators (`"1,000 KB"`), exponents (`"1e3 B"`), or a size that does not fit in an `int` (`"8 EiB"`).
:::

## Money

`Pharaonic\Readable\Money` formats amounts for display. It does no arithmetic and no exchange rates.

### Formatting

Without a locale, the ISO 4217 code comes first and the currency's minor units decide the decimals:

```php title="example.php"
Money::format(100, 'USD');      // "USD 100.00"
Money::format(1234.5, 'USD');   // "USD 1,234.50"
Money::format(1234.5, 'JPY');   // "JPY 1,235"
Money::format(1.5, 'KWD');      // "KWD 1.500"
Money::format(-20, 'EGP');      // "-EGP 20.00"
Money::format(1, 'usd');        // "USD 1.00"
```

Override the decimals with `$decimals`:

```php title="example.php"
Money::format(1234.5, 'USD', decimals: 0);  // "USD 1,235"
Money::format(1234.5, 'JPY', decimals: 2);  // "JPY 1,234.50"
```

### With a locale

Intl picks the symbol, its position and the separators:

```php title="example.php"
Money::format(1234.5, 'USD', locale: 'en_US');   // "$1,234.50"
Money::format(-1234.5, 'USD', locale: 'en_US');  // "-$1,234.50"
Money::format(1234.5, 'JPY', locale: 'en_US');   // "¥1,235"
Money::format(1234.5, 'EUR', locale: 'de_DE');   // "1.234,50 €"
```

### Compact amounts

```php title="example.php"
Money::compact(1500000, 'USD');  // "USD 1.5M"
Money::compact(-2500, 'EUR');    // "-EUR 2.5K"
Money::compact(999, 'EGP');      // "EGP 999"
```

### Minor units

`Money::fractionDigits()` returns the ISO 4217 number of decimals for a currency:

```php title="example.php"
Money::fractionDigits('USD');  // 2
Money::fractionDigits('JPY');  // 0
Money::fractionDigits('KWD');  // 3
Money::fractionDigits('CLF');  // 4
```

Currencies with 0 decimals: `BIF`, `CLP`, `DJF`, `GNF`, `ISK`, `JPY`, `KMF`, `KRW`, `PYG`, `RWF`, `UGX`, `UYI`, `VND`, `VUV`, `XAF`, `XOF`, `XPF`. With 3: `BHD`, `IQD`, `JOD`, `KWD`, `LYD`, `OMR`, `TND`. With 4: `CLF`, `UYW`. Every other code uses 2.

:::warning Currency codes
The currency must be three letters (any case). Anything else, such as `"$"` or `"dollars"`, throws `InvalidArgumentException`. Well-formed codes that aren't in ISO 4217 are accepted and use 2 decimals.
:::

## Durations

`Pharaonic\Readable\Duration` writes lengths of time in English.

### From seconds

```php title="example.php"
Duration::format(0);         // "0 seconds"
Duration::format(59);        // "59 seconds"
Duration::format(3661);      // "1 hour 1 minute 1 second"
Duration::format(187200);    // "2 days 4 hours"
Duration::format(604800);    // "1 week"
Duration::format(31536000);  // "1 year"
Duration::format(-3661);     // "1 hour 1 minute 1 second"
```

`format()` uses fixed-length units only: a year is 365 days, then weeks, days, hours, minutes and seconds. It never uses months, because a month has no fixed length: 29 days is `"4 weeks 1 day"`. The sign is ignored.

### Between two moments

`Duration::between()` uses the real calendar through PHP's `DateTimeInterface::diff()`, so it does report months. It accepts `DateTimeInterface` objects, Unix timestamps and any string `DateTimeImmutable` understands, in any order:

```php title="example.php"
Duration::between('2024-01-01', '2025-03-15');  // "1 year 2 months 2 weeks"
Duration::between('2024-02-01', '2024-03-01');  // "1 month"
Duration::between(0, 3661);                     // "1 hour 1 minute 1 second"
Duration::between($order->created_at, new DateTimeImmutable());
```

Moments in different time zones are compared as instants.

:::warning Daylight saving time
Within one time zone, whole days follow the wall clock: 12:00 to 12:00 across a DST change is `"1 day"`, even though 23 hours elapsed. Hours count the time that actually elapsed: 00:00 → 06:00 on a spring-forward day is `"5 hours"`.
:::

### Options

Both methods take the same three options after their main arguments:

| Option | Default | Effect |
| --- | --- | --- |
| `?int $parts` | `null` (all) | Keep only the largest non-zero units. Lower units are cut off, not rounded. |
| `bool $short` | `false` | Short units: `y`, `mo`, `w`, `d`, `h`, `m`, `s`. |
| `string $separator` | `' '` | Text between units. |

```php title="example.php"
Duration::format(90061, parts: 2);         // "1 day 1 hour"
Duration::format(7199, parts: 2);          // "1 hour 59 minutes"
Duration::format(3661, short: true);       // "1h 1m 1s"
Duration::format(3661, separator: ', ');   // "1 hour, 1 minute, 1 second"
Duration::between('2024-01-01', '2025-03-15', parts: 2, short: true); // "1y 2mo"
```

`parts` must be `1` or greater; `0` throws `InvalidArgumentException`.

## Strings

`Pharaonic\Readable\Str` has one helper, for the initials you show on avatars and badges.

### Initials

`Str::initials()` takes the first letter or digit of each whitespace-separated word and uppercases it:

```php title="example.php"
Str::initials('Moamen Eltouny');   // "ME"
Str::initials('moamen eltouny');   // "ME"
Str::initials('Raggi');            // "R"
Str::initials('élise ößler');      // "ÉÖ"
Str::initials('3M Company');       // "3C"
```

With more words than `$limit` (`2` by default), it keeps the first `$limit - 1` words and the last one:

```php title="example.php"
Str::initials('John Ronald Reuel Tolkien');     // "JT"
Str::initials('John Ronald Reuel Tolkien', 3);  // "JRT"
Str::initials('John Ronald Reuel Tolkien', 1);  // "J"
```

Leading punctuation is skipped (`'(Ada) "Lovelace"'` → `"AL"`), words with no letters or digits are ignored (`'Ada & Lovelace'` → `"AL"`), a hyphenated word counts as one word, and combining marks stay with their letter. An empty or whitespace-only name returns `""`.

:::warning Invalid input
A `$limit` below `1` or a name that isn't valid UTF-8 throws `InvalidArgumentException`.
:::

## Arrays

`Pharaonic\Readable\Arr` answers three common questions about an array's shape.

### Only nulls?

`Arr::isNull()` is `true` when every value is `null`. The check is strict: `false`, `0` and `''` are not null.

```php title="example.php"
Arr::isNull([null, null]);  // true
Arr::isNull([null, 0]);     // false
Arr::isNull([false]);       // false
Arr::isNull([]);            // true
```

An empty array has no non-null value, so it returns `true`.

### Nested arrays?

`Arr::isMultidimensional()` is `true` when at least one value is an array, including an empty one:

```php title="example.php"
Arr::isMultidimensional([1, 2]);              // false
Arr::isMultidimensional([1, [2]]);            // true
Arr::isMultidimensional(['x' => ['y' => 1]]); // true
Arr::isMultidimensional(['a' => []]);         // true
Arr::isMultidimensional([]);                  // false
```

### A list?

`Arr::isList()` is `true` when the keys are `0, 1, 2, …` in order:

```php title="example.php"
Arr::isList([10, 20, 30]);           // true
Arr::isList([]);                     // true
Arr::isList([1 => 'a']);             // false
Arr::isList([1 => 'b', 0 => 'a']);   // false
Arr::isList(['a' => 1]);             // false
```

:::info Numeric string keys
PHP converts the key `'0'` to the integer `0` when it builds the array, so `Arr::isList(['0' => 'a'])` is `true`.
:::

## API Reference

Every method is `public static`. Methods marked *throws* raise `InvalidArgumentException` for invalid input; any method with a `$locale` raises `Pharaonic\Readable\Exceptions\MissingIntlExtension` when a locale is passed without `ext-intl`.

### `Pharaonic\Readable\Number`

| Method | Description | Returns |
| --- | --- | --- |
| `format(int\|float $number, int $decimals = 0, bool $trimZeros = false, ?string $locale = null)` | Group thousands with a fixed number of decimals; `trimZeros` drops trailing fraction zeros. | `string` |
| `compact(int\|float $number, int $decimals = 1)` | Shorten with `K`, `M`, `B` or `T`, at most `$decimals` fraction digits. | `string` |
| `percentage(int\|float $ratio, int $decimals = 0, ?string $locale = null)` | Format a ratio (`1` = 100%) as a percentage. | `string` |
| `ordinal(int $number, ?string $locale = null)` | `1st`, `2nd`, `3rd`, `4th`, … | `string` |
| `spell(int\|float $number, ?string $locale = null)` | The number in words. | `string` |

### `Pharaonic\Readable\Bytes`

| Method | Description | Returns |
| --- | --- | --- |
| `format(int\|float $bytes, int $decimals = 2, bool $binary = false, ?string $locale = null)` | SI (`KB`) or, with `$binary`, IEC (`KiB`) size. | `string` |
| `parse(string $size)` | Readable size back to bytes, e.g. `'10 MB'` → `10000000`. *Throws.* | `int` |

### `Pharaonic\Readable\Money`

| Method | Description | Returns |
| --- | --- | --- |
| `format(int\|float $amount, string $currency, ?int $decimals = null, ?string $locale = null)` | Amount with its ISO 4217 code (or the locale's symbol); `$decimals` overrides the currency's minor units. *Throws.* | `string` |
| `compact(int\|float $amount, string $currency, int $decimals = 1)` | Short amount, e.g. `USD 1.5M`. *Throws.* | `string` |
| `fractionDigits(string $currency)` | ISO 4217 minor units of a currency. *Throws.* | `int` |

### `Pharaonic\Readable\Duration`

| Method | Description | Returns |
| --- | --- | --- |
| `format(int $seconds, ?int $parts = null, bool $short = false, string $separator = ' ')` | Seconds in years (365 days), weeks, days, hours, minutes and seconds. *Throws.* | `string` |
| `between(DateTimeInterface\|int\|string $start, DateTimeInterface\|int\|string $end, ?int $parts = null, bool $short = false, string $separator = ' ')` | Calendar difference between two moments, in any order. *Throws.* | `string` |

### `Pharaonic\Readable\Str`

| Method | Description | Returns |
| --- | --- | --- |
| `initials(string $name, int $limit = 2)` | Uppercase initials of a name. *Throws.* | `string` |

### `Pharaonic\Readable\Arr`

| Method | Description | Returns |
| --- | --- | --- |
| `isNull(array $array)` | Every value is `null` (`true` for `[]`). | `bool` |
| `isMultidimensional(array $array)` | At least one value is an array. | `bool` |
| `isList(array $array)` | Keys are `0, 1, 2, …` in order. | `bool` |

### Exceptions

| Class | Extends | Thrown when |
| --- | --- | --- |
| `Pharaonic\Readable\Exceptions\MissingIntlExtension` | `RuntimeException` | A `$locale` is passed but `ext-intl` isn't loaded. |
| `InvalidArgumentException` (PHP) | `LogicException` | `INF`/`NAN`, decimals below 0 or above 100, `parts` or `limit` below 1, a malformed currency code, an unparsable size or date, invalid UTF-8, or a locale Intl rejects. |

## Examples

### 1. A file list

Show each upload's size and age next to its name.

```php title="src/Uploads/FileRow.php"
use Pharaonic\Readable\{Bytes, Duration};

function fileRow(string $path): string
{
    $size = Bytes::format(filesize($path), 1, binary: true);
    $age = Duration::between(filemtime($path), time(), parts: 1);

    return sprintf('%s · %s · %s ago', basename($path), $size, $age);
}

// "report.pdf · 2.4 MiB · 3 days ago"
```

### 2. Dashboard stat cards

Big numbers stay short and percentages stay honest about rounding.

```php title="src/Dashboard/Stats.php"
use Pharaonic\Readable\Number;

$cards = [
    'Visitors'   => Number::compact(1284503),           // "1.3M"
    'Signups'    => Number::format(48210),              // "48,210"
    'Conversion' => Number::percentage(48210 / 1284503, 2), // "3.75%"
    'Rank'       => Number::ordinal(3),                 // "3rd"
];
```

### 3. Invoices in the customer's locale

The same amount, formatted for each customer, with a deterministic fallback when you don't know their locale.

- ===Invoice

  ```php title="src/Billing/InvoiceLine.php"
  use Pharaonic\Readable\Money;

  final class InvoiceLine
  {
      public function __construct(
          public float $amount,
          public string $currency,
      ) {}

      public function total(?string $locale = null): string
      {
          return Money::format($this->amount, $this->currency, locale: $locale);
      }
  }
  ```

- ===Usage

  ```php title="example.php"
  $line = new InvoiceLine(1234.5, 'EUR');

  $line->total();          // "EUR 1,234.50"
  $line->total('de_DE');   // "1.234,50 €"
  $line->total('en_US');   // "€1,234.50"

  (new InvoiceLine(1234.5, 'JPY'))->total(); // "JPY 1,235"
  ```

### 4. Avatar placeholders

Users without a photo get their initials.

```php title="src/Users/Avatar.php"
use Pharaonic\Readable\Str;

function avatarLabel(string $displayName): string
{
    return Str::initials($displayName) ?: '?';
}

avatarLabel('Moamen Eltouny');  // "ME"
avatarLabel('   ');             // "?"
```

### 5. Upload limits from configuration

Keep limits human-readable in configuration, parse them once, and show them back to the user.

```php title="src/Uploads/Limit.php"
use Pharaonic\Readable\Bytes;

$limit = Bytes::parse(getenv('UPLOAD_LIMIT') ?: '25 MB');   // 25000000

if ($file['size'] > $limit) {
    throw new RuntimeException(sprintf(
        'The file is %s; the limit is %s.',
        Bytes::format($file['size']),   // "31.46 MB"
        Bytes::format($limit),          // "25 MB"
    ));
}
```

## Troubleshooting

### `MissingIntlExtension` is thrown

You passed a `$locale` but the intl extension isn't loaded. Install and enable `ext-intl`, or drop the locale argument to use the built-in English formatter. Check with `php -m | grep intl`.

### A string comparison with Intl output fails

Intl puts a no-break space (U+00A0) or a narrow no-break space (U+202F) in some formats, such as `"1.234,50 €"` or `"75,6 %"`. Compare against the same characters, or replace them with a normal space before comparing. The exact space can change between ICU versions.

### `Bytes::format(1024)` returns `"1.02 KB"`

`KB` is 1000 bytes. For 1024-based units pass `binary: true`: `Bytes::format(1024, binary: true)` returns `"1 KiB"`.

### `Number::percentage(75)` returns `"7,500%"`

`percentage()` expects a ratio where `1` is 100%. Pass `0.75`, or divide your percent value by 100.

### `Duration::format()` never shows months

Months have no fixed length, so a bare number of seconds can't be split into them correctly. Use `Duration::between()` with two dates when you need calendar months.

### `Bytes::parse()` throws for `"10K"` or `"10 Mbit"`

A unit prefix needs a `B` (`10 KB`, `10 KiB`), and bits aren't bytes. Parsing also rejects thousands separators, exponents and sizes that don't fit in an `int`.

### `Money::format()` throws for `"$"` or `"dollars"`

The currency must be a three-letter ISO 4217 code such as `USD`. Map symbols or names to codes before formatting.

### `Duration::between()` throws for a date string

The string must be something `new DateTimeImmutable($string)` can read. Pass a `DateTimeInterface` or a Unix timestamp when your input uses another format.

## Upgrade Guide

Readable has one release line per PHP version, and every line has the same classes, methods and output. This page covers the `8.6.x` line, for PHP 8.6.

### Patch Releases

Patch releases such as `8.6.0` to `8.6.1` never break your code. Update with:

```bash no-line-numbers
composer update pharaonic/php-readable
```

Output changes only to fix a bug, and every such change is listed in the changelog.

### Moving To Another PHP Version

No code changes are needed. Composer picks the line that matches your PHP version, so after upgrading PHP run `composer update pharaonic/php-readable`.

The constraint that `composer require` writes (for example `^8.6`) already allows the newer lines. If you pinned a line with a tilde constraint such as `~8.6.0`, widen it first, or Composer stays on `8.6.x` and cannot install on the new PHP version.

### Changelog

Every release is listed in the [changelog](https://github.com/Pharaonic/php-readable/blob/8.5.x/CHANGELOG.md) and on the [GitHub releases](https://github.com/Pharaonic/php-readable/releases) page.
