PHPackages                             internal/toml - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. internal/toml

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

internal/toml
=============

TOML 1.0/1.1 parser and encoder

1.1.3(4d ago)4115.9k↑14.8%[1 issues](https://github.com/php-internal/toml/issues)3BSD-3-ClausePHPPHP &gt;=8.1CI failing

Since Oct 23Pushed 4d ago1 watchersCompare

[ Source](https://github.com/php-internal/toml)[ Packagist](https://packagist.org/packages/internal/toml)[ Fund](https://boosty.to/roxblnfk)[ RSS](/packages/internal-toml/feed)WikiDiscussions 1.x Synced 2d ago

READMEChangelog (8)Dependencies (17)Versions (9)Used By (3)

TOML for PHP
============

[](#toml-for-php)

[![Vibe Index](https://camo.githubusercontent.com/f9a2b87d7e86560d17ea715a4f1aed3ce914f1c77dc40005284744172812f5d6/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d566962652b496e646578266d6573736167653d302e3226636f6c6f723d323661663635267374796c653d666c61742d737175617265266c6f676f3d64617461253341696d616765253246737667253242786d6c25334262617365363425324350484e325a79423462577875637a30696148523063446f764c336433647935334d793576636d63764d6a41774d43397a646d636949485a705a58644362336739496a41674d4341794e4341794e4349675a6d6c736244306949325a6d5a694925324250484268644767675a44306954546b674e4342524f5341784d7941784f4341784d7942524f5341784d79413549444979494645354944457a494441674d544d6755546b674d544d674f53413049466f694c7a3438634746306143426b50534a4e4d546b674d5342524d546b674e6941794e434132494645784f5341324944453549444578494645784f534132494445304944596755544535494459674d546b674d53426149693825324250484268644767675a4430695454497749444530494645794d4341784f4341794e4341784f4342524d6a41674d5467674d6a41674d6a496755544977494445344944453249444534494645794d4341784f4341794d4341784e4342614969382532425043397a646d63253242)](https://github.com/roxblnfk/action-vibe-index)[![Sponsorship](https://camo.githubusercontent.com/16880ff340400027caaca88c657ec26fb2a64717d53368eb513de8d15cfcd0c2/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f7374796c653d666c61742d737175617265266c6162656c3d266d6573736167653d53706f6e736f7273686970266c6f676f3d426f6f737479266c6f676f436f6c6f723d776869746526636f6c6f723d253233463135463243)](https://boosty.to/roxblnfk)

TOML [1.0.0](https://toml.io/en/v1.0.0)/[1.1.0](https://toml.io/en/v1.1.0) parser and encoder for PHP 8.1+. Parse TOML files into PHP arrays or encode PHP data structures back to TOML format.

Installation
------------

[](#installation)

```
composer require internal/toml
```

[![PHP](https://camo.githubusercontent.com/f34a06ea7f905c08738590b8d6b9ed459ae91ad1090b68ffb2d9e86bf4177451/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f696e7465726e616c2f746f6d6c2e7376673f7374796c653d666c61742d737175617265266c6f676f3d706870)](https://packagist.org/packages/internal/toml)[![Latest Version on Packagist](https://camo.githubusercontent.com/9cceb54ff2b6b619b9026c2d40f4309debacb60ff0f7a32ca03033a647d51531/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696e7465726e616c2f746f6d6c2e7376673f7374796c653d666c61742d737175617265266c6f676f3d7061636b6167697374)](https://packagist.org/packages/internal/toml)[![License](https://camo.githubusercontent.com/b86d8bcde488a07a523a61c97f1666b5daf29c9112558cfd4b58a92bf96abfe0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f696e7465726e616c2f746f6d6c2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Total Destroys](https://camo.githubusercontent.com/b4f3249f71e4aceb955ddf32331c06979b0bbbd22634e54693c8a43ee5ebf8dc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f696e7465726e616c2f746f6d6c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/internal/toml/stats)

Quick Start
-----------

[](#quick-start)

### Parsing TOML

[](#parsing-toml)

```
use Internal\Toml\Toml;

// Parse to PHP array
$data = Toml::parseToArray( [
//         'host' => 'localhost',
//         'ports' => [8000, 8001, 8002],
//     ],
// ]
```

### Encoding to TOML

[](#encoding-to-toml)

```
use Internal\Toml\Toml;

$data = [
    'title' => 'Configuration',
    'database' => [
        'host' => 'localhost',
        'port' => 5432,
    ],
    'servers' => [
        ['name' => 'alpha', 'ip' => '10.0.0.1'],
        ['name' => 'beta', 'ip' => '10.0.0.2'],
    ],
];

$toml = (string) Toml::encode($data);

// Output:
// title = 'Configuration'
//
// [database]
// host = 'localhost'
// port = 5432
//
// [[servers]]
// name = 'alpha'
// ip = '10.0.0.1'
//
// [[servers]]
// name = 'beta'
// ip = '10.0.0.2'
```

### Working with AST

[](#working-with-ast)

```
use Internal\Toml\Toml;

// Parse to AST (Abstract Syntax Tree)
$document = Toml::parse('key = "value"');

// Access nodes
foreach ($document->nodes as $node) {
    // Work with Entry, Table, TableArray nodes
}

// Convert to array
$array = $document->toArray();

// Serialize back to TOML
$toml = (string) $document;
```

### Round-Trip Conversion

[](#round-trip-conversion)

```
// Parse → Modify → Encode
$document = Toml::parse($tomlString);
$data = $document->toArray();

// Modify data
$data['new_key'] = 'new_value';

// Encode back
$newToml = (string) Toml::encode($data);

// Perfect round-trip preservation
$parsed = Toml::parseToArray($newToml);
```

Examples
--------

[](#examples)

### DateTime Support

[](#datetime-support)

```
$data = [
    'created' => new DateTimeImmutable('1979-05-27T07:32:00Z'),
    'updated' => new DateTimeImmutable('2024-01-15T10:30:00+03:00'),
];

$toml = (string) Toml::encode($data);
// created = 1979-05-27T07:32:00Z
// updated = 2024-01-15T10:30:00+03:00
```

### JsonSerializable Support

[](#jsonserializable-support)

```
$object = new class implements JsonSerializable {
    public function jsonSerialize(): array {
        return ['name' => 'Example', 'value' => 123];
    }
};

$toml = (string) Toml::encode($object);
```

### Format Preservation

[](#format-preservation)

```
// Original TOML with hex number
$toml = 'magic = 0xDEADBEEF';

$document = Toml::parse($toml);
echo (string) $document;
// Output: magic = 0xDEADBEEF
// ✅ Original format preserved!
```

API
---

[](#api)

```
// Parse TOML string to Document AST
Toml::parse(string $toml): Document

// Parse TOML string to PHP array
Toml::parseToArray(string $toml): array

// Encode PHP array or JsonSerializable to TOML
Toml::encode(array|JsonSerializable $data): Stringable
```

Features
--------

[](#features)

- Full [TOML v1.1.0](https://toml.io/en/v1.1.0) spec compliance
- Strings: basic, literal, multiline, all escape sequences including `\e` and `\xHH`
- Numbers: integers (decimal, hex, octal, binary), floats, special values (`inf`, `nan`)
- Date-time: offset, local date-time, local date, local time (seconds optional)
- Tables, inline tables (multi-line with trailing commas), arrays of tables, dotted keys
- Comments preservation
- Format-preserving round-trips (hex numbers stay hex, etc.)
- Encoder outputs TOML v1.0-compatible format for maximum interoperability

Built with [Claude Code](https://claude.com/claude-code)

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance94

Actively maintained with recent releases

Popularity37

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~31 days

Recently: every ~22 days

Total

9

Last Release

4d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/110fa17dca123e71e4ef4132d1d6a66d20058a07fc6118e716dd67dd4316e886?d=identicon)[roxblnfk](/maintainers/roxblnfk)

---

Top Contributors

[![roxblnfk](https://avatars.githubusercontent.com/u/4152481?v=4)](https://github.com/roxblnfk "roxblnfk (38 commits)")

---

Tags

hacktoberfesttoml

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/internal-toml/health.svg)

```
[![Health](https://phpackages.com/badges/internal-toml/health.svg)](https://phpackages.com/packages/internal-toml)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
