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.5.0(1w ago)02MIT OR Apache-2.0PHPPHP ^7.4 || ^8.0CI passing

Since Apr 26Pushed 1w 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 1w ago

READMEChangelog (8)Dependencies (1)Versions (8)Used By (0)

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

[](#ktav--php-bindings)

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

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``:i ``int` if it fits, else `string` (PHP has no native bigint — wrap your own GMP / BCMath if you need arithmetic).`:f ``float`bare 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

36

—

LowBetter than 79% of packages

Maintenance98

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity33

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

7

Last Release

12d 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 (12 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.8k260.4M292](/packages/masterminds-html5)[hassankhan/config

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

1.0k13.7M181](/packages/hassankhan-config)[laktak/hjson

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

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

Nginx configuration files processor.

6935.7k1](/packages/romanpitak-nginx-config-processor)[metroplex-systems/edifact

Parser and Serializer for UN/EDIFACT messages

36408.3k](/packages/metroplex-systems-edifact)[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.

64124.3k1](/packages/m1-vars)

PHPackages © 2026

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