PHPackages                             devium/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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. devium/toml

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

devium/toml
===========

A PHP encoder/decoder for TOML compatible with specification 1.0.0

1.0.6(1y ago)3968.9k—9.1%28MITPHPPHP &gt;=8.1CI passing

Since Aug 7Pushed 7mo ago2 watchersCompare

[ Source](https://github.com/vanodevium/toml)[ Packagist](https://packagist.org/packages/devium/toml)[ GitHub Sponsors](https://github.com/vanodevium)[ RSS](/packages/devium-toml/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (7)Versions (8)Used By (8)

Stand With Ukraine 🇺🇦
=====================

[](#stand-with-ukraine-)

[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner-direct-single.svg)](https://vshymanskyy.github.io/StandWithUkraine/)

Devium/Toml
===========

[](#deviumtoml)

[![Tests status](https://camo.githubusercontent.com/ef7a6e7e197d18da2456911eed86a4c581cde2902b46f3d75e1ba9040e8bead0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f76616e6f64657669756d2f746f6d6c2f63692e79616d6c3f76312e302e36267374796c653d666c61742d737175617265266c6162656c3d7465737473)](https://github.com/vanodevium/toml)[![Latest Version](https://camo.githubusercontent.com/1fbd8404982f7346b04c1f6e14e53010cb99c0e7059d36dfba3bc15b0915ca89/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f64657669756d2f746f6d6c3f76312e302e36267374796c653d666c61742d737175617265266c6162656c3d737461626c65)](https://packagist.org/packages/devium/toml)[![Downloads](https://camo.githubusercontent.com/fc96d4fcf5a9979e7cf890933ff22200779fecd52d7e42bdf11d9ec3900fe274/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f64657669756d2f746f6d6c3f76312e302e36267374796c653d666c61742d737175617265)](https://packagist.org/packages/devium/toml)[![License](https://camo.githubusercontent.com/92e45fac89e7d08be71a0b86c4998d8c950c24e63c5abf837e965287cc569c7d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f64657669756d2f746f6d6c3f76312e302e36267374796c653d666c61742d737175617265)](https://packagist.org/packages/devium/toml)

A robust and efficient PHP library for encoding and decoding [TOML](https://github.com/toml-lang/toml)compatible with [v1.0.0](https://toml.io/en/v1.0.0)

> This library tries to support the TOML specification as much as possible.

Overview
--------

[](#overview)

This library provides a comprehensive solution for working with TOML in PHP applications

Features
--------

[](#features)

- Encoding PHP arrays and objects to TOML format
- Decoding TOML strings into PHP data structures
- Preserves data types as specified in TOML
- Handles complex nested structures
- Supports TOML datetime formats
- Error handling with informative messages

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

[](#installation)

You can install this library via composer:

```
composer require devium/toml
```

Usage
-----

[](#usage)

Decoding:

```
$toml =  "TOML Example",
  "owner" => [
    "name" => "Tom Preston-Werner",
    "dob" => "1979-05-27T15:32:00.000Z",
  ],
];

dump(\Devium\Toml\Toml::encode($data));
// or use global helper
dump(toml_encode($data));
```

About TOML datetime formats
---------------------------

[](#about-toml-datetime-formats)

This library tries to parse TOML datetime formats into next variants (according to the specification):

- `Devium\Toml\TomlDateTime` (for the [offset date time](https://toml.io/en/v1.0.0#offset-date-time))
- `Devium\Toml\TomlLocalDatetime` (for the [local date time](https://toml.io/en/v1.0.0#local-date-time))
- `Devium\Toml\TomlLocalDate` (for the [local date](https://toml.io/en/v1.0.0#local-date))
- `Devium\Toml\TomlLocalTime` (for the [local time](https://toml.io/en/v1.0.0#local-time))

Example:

```
offset-date-time-1 = 1979-05-27T07:32:00Z
offset-date-time-2 = 1979-05-27T00:32:00-07:00
offset-date-time-3 = 1979-05-27T00:32:00.999999-07:00
offset-date-time-4 = 1979-05-27 07:32:00Z

local-date-time-1 = 1979-05-27T07:32:00
local-date-time-2 = 1979-05-27T00:32:00.999999

local-date-1 = 1979-05-27

local-time-1 = 07:32:00
local-time-2 = 00:32:00.999999
```

If you use

```
dump(toml_decode($toml, true));
```

TOML will be parsed into array

```
array:9 [
  "offset-date-time-1" => Devium\Toml\TomlDateTime @296638320 {#29
    date: 1979-05-27 07:32:00.0 +00:00
  }
  "offset-date-time-2" => Devium\Toml\TomlDateTime @296638320 {#35
    date: 1979-05-27 00:32:00.0 -07:00
  }
  "offset-date-time-3" => Devium\Toml\TomlDateTime @296638320 {#41
    date: 1979-05-27 00:32:00.999999 -07:00
  }
  "offset-date-time-4" => Devium\Toml\TomlDateTime @296638320 {#47
    date: 1979-05-27 07:32:00.0 +00:00
  }
  "local-date-time-1" => Devium\Toml\TomlLocalDateTime {#55
    +year: 1979
    +month: 5
    +day: 27
    +hour: 7
    +minute: 32
    +second: 0
    +millisecond: 0
  }
  "local-date-time-2" => Devium\Toml\TomlLocalDateTime {#61
    +year: 1979
    +month: 5
    +day: 27
    +hour: 0
    +minute: 32
    +second: 0
    +millisecond: 999
  }
  "local-date-1" => Devium\Toml\TomlLocalDate {#59
    +year: 1979
    +month: 5
    +day: 27
  }
  "local-time-1" => Devium\Toml\TomlLocalTime {#70
    +millisecond: 0
    +hour: 7
    +minute: 32
    +second: 0
  }
  "local-time-2" => Devium\Toml\TomlLocalTime {#77
    +millisecond: 999
    +hour: 0
    +minute: 32
    +second: 0
  }
]
```

Each class implements `Stringable` interface.

`TomlLocal*` classes are marked with `TomlDateTimeInterface` for usability. Each class has public properties.

There is `TomlDateTime` class to support TOML offset date time format also.

Of course any `DateTimeInterface` or `TomlDateTimeInterface` are encoded into TOML datetime string. So

```
$data = [
    'DateTimeInterface' => new DateTimeImmutable('1979-05-27T07:32:00Z'),
    'TomlDateTimeInterface' => new TomlDateTime('1979-05-27T07:32:00Z'),
];
```

will be encoded into

```
DateTimeInterface = 1979-05-27T07:32:00.000Z
TomlDateTimeInterface = 1979-05-27T07:32:00.000Z
```

About informative errors
------------------------

[](#about-informative-errors)

If there is parsing error, `TomlError` has the approximate location of the problem in the message. Something like:

```
Invalid TOML document: unexpected non-numeric value

5:  [owner]
6:  name = Tom Preston-Werner
             ^
7:  dob = 1979-05-31T07:32:00-08:00
```

Else it has message about whole input.

About floating-point values
---------------------------

[](#about-floating-point-values)

The decoder returns each floating-point value as a string by default.

You can force it to return a float type by setting the **$asFloat** argument:

```
toml_decode($toml, asFloat: true);
// or
\Devium\Toml\Toml::decode($toml, asFloat: true);
```

About NULL
----------

[](#about-null)

**TOML does not support null values.**

If the array contains a null value, an exception will be thrown.

The only thing possible is a null value for the keys in the tables. Such keys are simply skipped during encoding.

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request

License
-------

[](#license)

**devium/toml** is open-sourced software licensed under the [MIT license](./LICENSE.md).

[Vano Devium](https://github.com/vanodevium/)

---

Made with ❤️ in Ukraine

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance57

Moderate activity, may be stable

Popularity42

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity53

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

Recently: every ~63 days

Total

7

Last Release

391d ago

PHP version history (2 changes)1.0.0PHP &gt;=8.2

1.0.4PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/b77aace17f0e03d279990524cc1a53393e5fe96f1367278abef40592d2c9b607?d=identicon)[devium](/maintainers/devium)

---

Top Contributors

[![vanodevium](https://avatars.githubusercontent.com/u/16780069?v=4)](https://github.com/vanodevium "vanodevium (57 commits)")

---

Tags

parserencodedecodetoml

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[yethee/tiktoken

PHP version of tiktoken

1583.1M15](/packages/yethee-tiktoken)[yosymfony/toml

A PHP parser for TOML compatible with specification 0.4.0

2081.7M71](/packages/yosymfony-toml)[gioni06/gpt3-tokenizer

PHP package for Byte Pair Encoding (BPE) used by GPT-3.

85537.5k8](/packages/gioni06-gpt3-tokenizer)[doctrine/rst-parser

PHP library to parse reStructuredText documents and generate HTML or LaTeX documents.

64233.6k9](/packages/doctrine-rst-parser)[kherge/json

Encodes, decodes, and validates JSON data.

61226.6k6](/packages/kherge-json)[leonelquinteros/php-toml

PHP parser for TOML language ( https://github.com/toml-lang/toml )

266.7k](/packages/leonelquinteros-php-toml)

PHPackages © 2026

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