PHPackages                             leon/leon - 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. leon/leon

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

leon/leon
=========

LEON serialization for PHP.

06PHP

Since Aug 6Pushed 10y ago1 watchersCompare

[ Source](https://github.com/raypulver/phpleon)[ Packagist](https://packagist.org/packages/leon/leon)[ RSS](/packages/leon-leon/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

phpleon
=======

[](#phpleon)

This is the PHP implementation of LEON. It works identically to the JavaScript version, except it exposes the functions `leon_encode` and `leon_decode`. A Channel object can be constructed by calling `new LEON\Channel($template)`. A Channel object contains an `encode` and a `decode` method, which can be used to serialize data according to the template. Type constants to be passed to a LEON\\Channel are defined at the top of leon.php.

Usage
-----

[](#usage)

```
require_once 'leon.php';
$payload = array(
  'firstkey' => 5,
  'secondkey' => true,
  'thirdkey' => 'just a string'
);
leon_decode(leon_encode($payload)) == $payload;
// true

```

LEON provides special classes to serialize/deserialize special JavaScript values. The `LEON\Date` constructor accepts a timestamp which can be accessed via `$date->timetamp`. The `LEON\RegExp` constructor accepts a string representation of the RegExp (without the delimiting slashes) and can also take a second argument representing the RegExp modifiers. A RegExp object stores the match pattern in `$regexp->pattern` and the modifier in `$regexp->modifier`. A RegExp object also has a `toString()` method which behaves identically to JavaScript's `RegExp#toString()`.

The value of `NaN` is deserialized into an instance of `LEON\NaN` and `undefined` deserializes to an instance of `LEON\Undefined`. If you want to serialize/deserialize a `Buffer` object you must use the `LEON\StringBuffer` class, which provides all the methods that a Node.js `Buffer` provides for reading and writing data.

In addition to arrays, you can also serialize objects, but only public properties will be serialized, and it will treat the data as an associative array.

If you want to create a template to be passed to `LEON\Channel` dynamically, you can pass an example value of the data you wish to serialize to `LEON\Channel::toTemplate`.

License
-------

[](#license)

MIT

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/0f0cf139cc0dfaf6d6119a01ed83abaa3d835119542cf1f1fa820eb54e79a641?d=identicon)[raypulver](/maintainers/raypulver)

---

Top Contributors

[![raypulver](https://avatars.githubusercontent.com/u/7101146?v=4)](https://github.com/raypulver "raypulver (21 commits)")

### Embed Badge

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

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

###  Alternatives

[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M65](/packages/sabberworm-php-css-parser)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)[jms/serializer-bundle

Allows you to easily serialize, and deserialize data of any complexity

1.8k89.3M627](/packages/jms-serializer-bundle)[hassankhan/config

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

97513.5M170](/packages/hassankhan-config)[meyfa/php-svg

Read, edit, write, and render SVG files with PHP

54613.9M42](/packages/meyfa-php-svg)

PHPackages © 2026

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