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 1.0.0 and 1.1.0

1.1.0(4mo ago)4087.5k↓11.5%4[2 PRs](https://github.com/vanodevium/toml/pulls)11MITPHPPHP &gt;=8.2CI passing

Since Aug 7Pushed 4mo 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 2w ago

READMEChangelogDependencies (14)Versions (9)Used By (11)

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) and [v1.1.0](https://toml.io/en/v1.1.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.1.0#offset-date-time))
- `Devium\Toml\TomlLocalDatetime` (for the [local date time](https://toml.io/en/v1.1.0#local-date-time))
- `Devium\Toml\TomlLocalDate` (for the [local date](https://toml.io/en/v1.1.0#local-date))
- `Devium\Toml\TomlLocalTime` (for the [local time](https://toml.io/en/v1.1.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.

About testing
-------------

[](#about-testing)

This library is tested with official [test cases](https://github.com/toml-lang/toml-test)

There is list of skipped rules:

- valid/key/quoted-unicode
- invalid/encoding/bad-utf8-in-comment
- invalid/encoding/bad-codepoint
- encoder/key/quoted-unicode
- encoder/spec-1.0.0/float-1
- encoder/float/max-int
- encoder/float/long

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

52

—

FairBetter than 96% of packages

Maintenance75

Regular maintenance activity

Popularity43

Moderate usage in the ecosystem

Community22

Small or concentrated contributor base

Maturity58

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

Recently: every ~150 days

Total

8

Last Release

136d 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 (60 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

[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.7k39.6k](/packages/matomo-matomo)[helsingborg-stad/municipio

A bootstrap theme for creating municipality sites.

4028.6k10](/packages/helsingborg-stad-municipio)[yethee/tiktoken

PHP version of tiktoken

1664.3M35](/packages/yethee-tiktoken)[yosymfony/toml

A PHP parser for TOML compatible with specification 0.4.0

2101.8M93](/packages/yosymfony-toml)[gioni06/gpt3-tokenizer

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

84607.8k15](/packages/gioni06-gpt3-tokenizer)[doctrine/rst-parser

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

64253.3k19](/packages/doctrine-rst-parser)

PHPackages © 2026

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