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 support for PHP

1.0.3(6mo ago)453.0k↓26.7%[1 issues](https://github.com/php-internal/toml/issues)2BSD-3-ClausePHPPHP &gt;=8.1CI passing

Since Oct 23Pushed 5mo agoCompare

[ Source](https://github.com/php-internal/toml)[ Packagist](https://packagist.org/packages/internal/toml)[ Patreon](https://patreon.com/roxblnfk)[ RSS](/packages/internal-toml/feed)WikiDiscussions 1.x Synced 1mo ago

READMEChangelog (4)Dependencies (5)Versions (5)Used By (2)

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

[](#toml-for-php)

[![Support](https://camo.githubusercontent.com/92a5c9c142a4b40702e8f5905faa1afae6cfc4f79c417502e83bce1e2c90cf5f/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f7374796c653d666c61742d737175617265266c6162656c3d537570706f7274266d6573736167653d254532253944254134266c6f676f3d47697448756226636f6c6f723d253233666530303836)](https://patreon.com/roxblnfk)

[TOML v1.0.0](https://toml.io/en/v1.0.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
```

What's supported
----------------

[](#whats-supported)

All TOML v1.0.0 features: strings (basic/literal/multiline), integers (decimal/hex/octal/binary), floats, booleans, datetime, arrays, tables, inline tables, dotted keys, comments.

The library preserves original formatting when doing round-trips (hex numbers stay hex, comments are kept, etc).

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

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance65

Regular maintenance activity

Popularity35

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity47

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 ~10 days

Total

5

Last Release

167d 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 (23 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)
```

###  Alternatives

[mrsuh/php-bison-skeleton

PHP skeleton for Bison

3810.4k1](/packages/mrsuh-php-bison-skeleton)

PHPackages © 2026

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