PHPackages                             knik/binn - 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. knik/binn

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

knik/binn
=========

Serialize to binary string.

v0.9.0(5y ago)78.7k—0%1[1 PRs](https://github.com/et-nik/binn-php/pulls)1GPL-3.0PHPPHP &gt;=7.2

Since Dec 28Pushed 2y agoCompare

[ Source](https://github.com/et-nik/binn-php)[ Packagist](https://packagist.org/packages/knik/binn)[ Docs](https://github.com/et-nik/binn-php)[ RSS](/packages/knik-binn/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (9)Used By (1)

Binn
====

[](#binn)

[![Build Status](https://camo.githubusercontent.com/da10704317ac576ff652442748800df1aae051b5f627340cbd30fb55e6db8b96/68747470733a2f2f7472617669732d63692e636f6d2f65742d6e696b2f62696e6e2d7068702e7376673f6272616e63683d6d6173746572)](https://travis-ci.comd/et-nik/binn-php)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/a9a0c16c93c4bd90e0f920f8735ab3741fb3a137610e76d746999e7f9842adac/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f65742d6e696b2f62696e6e2d7068702f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/et-nik/binn-php/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/92e93f890f7b4c2ef0e1a571183b9dd34927106a2d5825d070ab8bbf94c2101a/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f65742d6e696b2f62696e6e2d7068702f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/et-nik/binn-php/?branch=master)

PHP Class for serialize to binary string.

Original C Binn Library:

Binn Specification:

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

[](#installation)

```
composer require knik/binn
```

Examples
--------

[](#examples)

### Binn

[](#binn-1)

Sequential arrays:

```
use Knik\Binn\Binn;

$binn = new Binn();

// List
$array = [123, -456, 789];
$binnString = $binn->serialize($array);
$unserialized = $binn->unserialize($binnString); // Equal with $array
```

Numeric keys array:

```
$binn = new Binn();

// Map
$array = [1 => "add", 2 => [-12345, 6789]];
$binnString = $binn->serialize($array);
$unserialized = $binn->unserialize($binnString); // Equal with $array
```

String keys array:

```
$binn = new Binn();

// Object
$array = ["hello" => "world"];
$binnString = $binn->serialize($array);
$unserialized = $binn->unserialize($binnString); // Equal with $array
```

Mixed arrays:

```
$binn = new Binn();
$array = [ ["id" => 1, "name" => "John"], ["id" => 2, "name" => "Eric"] ]

// A list of objects
$binnString = $binn->serialize($array);
$unserialized = $binn->unserialize($binnString); // Equal with $array
```

Blob:

```
$binn = new Binn();
$file = fopen('/path/to/file.jpg', 'rb');

// Filedata in binn structure
$bin1 = $binn->serialize($file);

// Filedata in binn list structure
$bin2 = $binn->serialize(['file' => $file]);
```

### Symfony Serializer

[](#symfony-serializer)

You can use BinnEncoder with Symfony Serializer

```
use Knik\Binn\Encoder\BinnEncoder;
use Symfony\Component\Serializer\Serializer;

$encoders = [new BinnEncoder()];
$serializer = new Serializer([], $encoders);

$serializer->serialize("\x40\xD0\x06", 'binn');
```

### Original C library style

[](#original-c-library-style)

```
$binn = new BinnList();
$binn->addUint8(4);
$binn->addInt16(-8875);
$binn->addStr('text');

$serialized = $binn->serialize(); // \xE0\x0F\x03\x20\x04\x41\xDD\x55\xA0\x04text\x00
```

### Nested arrays

[](#nested-arrays)

```
$array = [2, true, [123, -456, 789]];

$binn = new BinnList();

// \xE0\x11\x03\x20\x02\x01\xE0\x0B\x03\x20\x7B\x41\xFE\x38\x40\x03\x15
$serialized = $binn->serialize($array);
```

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community9

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

Recently: every ~212 days

Total

7

Last Release

1887d ago

PHP version history (3 changes)0.1PHP &gt;=5.4

0.2.2PHP &gt;=5.6.3

v0.9.0PHP &gt;=7.2

### Community

Maintainers

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

---

Top Contributors

[![et-nik](https://avatars.githubusercontent.com/u/3670640?v=4)](https://github.com/et-nik "et-nik (67 commits)")

---

Tags

binbinaryphp-libraryserializationsymfony-componentserializebin

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/knik-binn/health.svg)

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

###  Alternatives

[opis/closure

A library that can be used to serialize closures (anonymous functions) and arbitrary data.

2.6k230.0M282](/packages/opis-closure)[zumba/json-serializer

Serialize PHP variables, including objects, in JSON format. Support to unserialize it too.

129743.7k13](/packages/zumba-json-serializer)[pmjones/throwable-properties

Copies properties of a Throwable to a serializable object.

1554.7k2](/packages/pmjones-throwable-properties)

PHPackages © 2026

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