PHPackages                             ktav-lang/ktav - 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. ktav-lang/ktav

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

ktav-lang/ktav
==============

PHP bindings for Ktav — a plain configuration format with three rules, zero indentation, and zero quoting. FFI over the reference Rust crate; no extension compilation on the consumer side.

v0.6.1(1mo ago)02MIT OR Apache-2.0PHPPHP ^7.4 || ^8.0CI passing

Since Apr 26Pushed 1mo agoCompare

[ Source](https://github.com/ktav-lang/php)[ Packagist](https://packagist.org/packages/ktav-lang/ktav)[ Docs](https://github.com/ktav-lang/php)[ RSS](/packages/ktav-lang-ktav/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (9)Dependencies (2)Versions (10)Used By (0)

ktav — PHP bindings
===================

[](#ktav--php-bindings)

[![Packagist](https://camo.githubusercontent.com/8e7e4bf79954c394f25dbeeb3dc21a8ffaec8993a1ba823660fa019a21b5d434/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b7461762d6c616e672f6b7461763f7374796c653d666c61742d737175617265266c6f676f3d7061636b6167697374266c6f676f436f6c6f723d7768697465266c6162656c3d5061636b6167697374)](https://packagist.org/packages/ktav-lang/ktav)[![CI](https://camo.githubusercontent.com/0bf4a79572dd821bc35283f19b0a6b8d81c32bf0ee046b145a4f51b659dd1b96/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6b7461762d6c616e672f7068702f63692e796d6c3f7374796c653d666c61742d737175617265266c6f676f3d676974687562266c6162656c3d4349)](https://github.com/ktav-lang/php/actions)[![License: MIT OR Apache-2.0](https://camo.githubusercontent.com/2360ddf8ed1dabbfd52c5c79bfb5096a1ccf28d612e9839c0517bcdd682011c9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542532304f522532304170616368652d2d322e302d626c75653f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/2360ddf8ed1dabbfd52c5c79bfb5096a1ccf28d612e9839c0517bcdd682011c9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542532304f522532304170616368652d2d322e302d626c75653f7374796c653d666c61742d737175617265)[![Playground](https://camo.githubusercontent.com/bbea7008c71706f91782d37491907ca7d65be3d38d87d516ca86e34cc06dfc87/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f706c617967726f756e642d7472792532306f6e6c696e652d3763336165643f7374796c653d666c61742d737175617265266c6f676f3d726f636b6574266c6f676f436f6c6f723d7768697465)](https://ktav-lang.github.io/)

**Languages:** **English** · [Русский](README.ru.md) · [简体中文](README.zh.md)

**Playground:** convert JSON / YAML / TOML / INI ⇄ Ktav in your browser at **[ktav-lang.github.io](https://ktav-lang.github.io/)**.

PHP bindings for the [Ktav configuration format](https://github.com/ktav-lang/spec). Thin wrapper around the reference Rust parser, loaded at runtime through the **[PHP FFI extension](https://www.php.net/manual/en/book.ffi.php)** — no PHP extension to compile, no PECL install. Plain Composer dependency, the native binary is fetched on first call.

Requires **PHP 7.4+** with `ext-ffi` enabled (default in CLI; web SAPIs need `ffi.enable=1` in `php.ini`).

Install
-------

[](#install)

```
composer require ktav-lang/ktav
```

Quick start
-----------

[](#quick-start)

### Parse — read typed values straight off the array

[](#parse--read-typed-values-straight-off-the-array)

```
use Ktav\Ktav;

$src =  'frontend',
    'port'  => 8443,
    'tls'   => true,
    'ratio' => 0.95,
    'upstreams' => [
        ['host' => 'a.example', 'port' => 1080],
        ['host' => 'b.example', 'port' => 1080],
    ],
    'notes' => null,
];
$text = Ktav::dumps($doc);
```

A complete runnable example lives in [`examples/basic.php`](examples/basic.php).

API
---

[](#api)

MethodPurpose`Ktav::loads(string $src): mixed`Parse a Ktav document.`Ktav::dumps(array $value): string`Render an associative array as Ktav text.`Ktav::nativeVersion(): string`Version of the loaded `ktav_cabi`.`KtavException` is thrown on any parse / render failure; the message is the UTF-8 string produced by the native parser.

Type mapping
------------

[](#type-mapping)

KtavPHP`null``null``true` / `false``bool`bare integer`int` if it fits, else `string` (PHP has no native bigint — wrap your own GMP / BCMath if you need arithmetic).bare decimal`float`other scalar`string``[ ... ]`sequential `array``{ ... }`associative `array` (insertion order preserved)To emit an arbitrary-precision integer, wrap the digit string yourself: `['big' => ['$i' => '9999999999999999999']]` — same envelope used on the wire between PHP and the native side.

Key escaping
------------

[](#key-escaping)

Since spec 0.6.0 a literal `.` or `:` inside a key segment is written with a backslash:

```
a\.b: v        # key is the single segment "a.b" → ["a.b" => "v"]
a\:b: v        # key contains a colon          → ["a:b" => "v"]
x.y\.z: v      # split on the first dot only   → ["x" => ["y.z" => "v"]]

```

A literal backslash in a key is `\\`.

How the native library is resolved
----------------------------------

[](#how-the-native-library-is-resolved)

On first call:

1. **`KTAV_LIB_PATH`** env var, if set.
2. **User cache** — `/ktav-php/v/`, downloaded on a previous call.
3. **GitHub Release download** — fetched once from `github.com/ktav-lang/php/releases/download/v/` and cached under (2). Requires network on first call after install.

`` is `%LOCALAPPDATA%` on Windows, `~/Library/Caches` on macOS, `$XDG_CACHE_HOME` or `~/.cache` on Linux.

Runtime support
---------------

[](#runtime-support)

- PHP 7.4 / 8.0 / 8.1 / 8.2 / 8.3+. Tested on the LTS lines on every CI run.
- Prebuilt binaries for: `linux/amd64`, `linux/arm64`, `darwin/amd64`, `darwin/arm64`, `windows/amd64`, `windows/arm64`.
- Linux distros must use glibc 2.17+ (zigbuild baseline). Alpine (musl) support is planned.

License
-------

[](#license)

MIT OR Apache-2.0 — see [LICENSE-MIT](LICENSE-MIT) and [LICENSE-APACHE](LICENSE-APACHE).

Other Ktav implementations
--------------------------

[](#other-ktav-implementations)

- [`spec`](https://github.com/ktav-lang/spec) — specification + conformance suite
- [`rust`](https://github.com/ktav-lang/rust) — reference Rust crate (`cargo add ktav`)
- [`csharp`](https://github.com/ktav-lang/csharp) — C# / .NET (`dotnet add package Ktav`)
- [`golang`](https://github.com/ktav-lang/golang) — Go (`go get github.com/ktav-lang/golang`)
- [`java`](https://github.com/ktav-lang/java) — Java / JVM (`io.github.ktav-lang:ktav` on Maven Central)
- [`js`](https://github.com/ktav-lang/js) — JS / TS (`npm install @ktav-lang/ktav`)
- [`python`](https://github.com/ktav-lang/python) — Python (`pip install ktav`)

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance90

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

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

Total

9

Last Release

49d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/14233546?v=4)[Arch-AI-tech](/maintainers/PHPCraftdream)[@PHPCraftdream](https://github.com/PHPCraftdream)

---

Top Contributors

[![PHPCraftdream](https://avatars.githubusercontent.com/u/14233546?v=4)](https://github.com/PHPCraftdream "PHPCraftdream (18 commits)")

---

Tags

bindingscomposerconfigconfig-formatconfigurationffiktavparserphprustconfigurationconfigparserserializerffiktav

### Embed Badge

![Health badge](/badges/ktav-lang-ktav/health.svg)

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

###  Alternatives

[masterminds/html5

An HTML5 parser and serializer.

1.8k269.7M327](/packages/masterminds-html5)[hassankhan/config

Lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files

1.0k13.8M189](/packages/hassankhan-config)[laktak/hjson

JSON for Humans. A configuration file format with relaxed syntax, fewer mistakes and more comments.

86245.3k14](/packages/laktak-hjson)[romanpitak/nginx-config-processor

Nginx configuration files processor.

6935.9k1](/packages/romanpitak-nginx-config-processor)[m1/vars

Vars is a simple to use and easily extendable configuration loader with in built loaders for ini, json, PHP, toml, XML and yaml/yml file types. It also comes with in built support for Silex and more frameworks to come soon.

69124.3k1](/packages/m1-vars)[metroplex-systems/edifact

Parser and Serializer for UN/EDIFACT messages

36410.4k](/packages/metroplex-systems-edifact)

PHPackages © 2026

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