PHPackages                             botanick/serializer - 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. botanick/serializer

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

botanick/serializer
===================

Library for serialization of any PHP structures (scalars, objects, arrays, etc.) into PHP primitives (scalars, arrays of scalars, arrays of arrays).

0162PHP

Since Feb 11Pushed 8y ago1 watchersCompare

[ Source](https://github.com/Botanick/serializer)[ Packagist](https://packagist.org/packages/botanick/serializer)[ RSS](/packages/botanick-serializer/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Serializer
==========

[](#serializer)

[![Build Status](https://camo.githubusercontent.com/d201915111d552b01cd3e1d1a1dc073fda3df6022ae3192527a90a5c2caa29bd/68747470733a2f2f7472617669732d63692e6f72672f426f74616e69636b2f73657269616c697a65722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Botanick/serializer)

This library allows you to serialize PHP structures of any complexity into PHP primitives: scalars, arrays, arrays of scalars, arrays of arrays, etc. The result can be then safely stored somewhere or passed anywhere using `serialize()`, `json_encode()` or any other way to convert plain arrays into string.

This library contains built-in serializers for:

- `null`
- scalars (bool, int, float, string)
- PHP `resource` type
- arrays and `\Traversable`
- `\DateTime`
- objects (which are flexibly configurable via custom configurations)

### Installation

[](#installation)

This library is managed via composer. You can install it by calling:

```
$ composer require botanick/serializer
```

or manually adding it to your `composer.json`:

```
    "require": {
        "botanick/serializer": "dev-master"
    }
```

### Usage

[](#usage)

Serializer usage is split into two general steps.

First of all, you should construct data serializers you are going to use. For example, if you are going to serialize only arrays of DateTimes, then your code will look like:

```
use Botanick\Serializer\Serializer;

$arraySerializer = new Serializer\DataSerializer\ArraySerializer();
$dateTimeSerializer = new Serializer\DataSerializer\DateTimeSerializer();
// for detailed info on DateTimeSerializer options see an according section
$dateTimeSerializer->setDefaultOptions(array('format' => 'Y-m-d H:i:s'));
```

Then you need serializer to know about data serializers it should use:

```
use Botanick\Serializer\Serializer;

$serializer = new Serializer\Serializer();
$serializer->addDataSerializer($arraySerializer, -9999);
$serializer->addDataSerializer($dateTimeSerializer, -8888);
```

That's all! Now you are able to serialize your data:

```
$data = array(
    new \DateTime(),
    'yesterday' => new \DateTime('1 day ago'),
    'dates' => array(
        'some-date' => \DateTime::createFromFormat('H:i:s d.m.Y', '11:22:33 01.02.2003'),
        'another-date' => \DateTime::createFromFormat('d.m.Y', '01.02.2003')
    )
);
$serializedData = $serializer->serialize($data);
var_export($serializedData);

// you will see something like this:
// array (
//   0 => '2015-12-08 16:42:54',
//   'yesterday' => '2015-12-07 16:42:54',
//   'dates' =>
//   array (
//     'some-date' => '2003-02-01 11:22:33',
//     'another-date' => '2003-02-01 16:42:54',
//   ),
// )
```

### Documentation

[](#documentation)

- Data serializers:
    - [NullSerializer](doc/Serializer/DataSerializer/NullSerializer.md)
    - [ScalarSerializer](doc/Serializer/DataSerializer/ScalarSerializer.md)
    - [ResourceSerializer](doc/Serializer/DataSerializer/ResourceSerializer.md)
    - [ArraySerializer](doc/Serializer/DataSerializer/ArraySerializer.md)
    - [DateTimeSerializer](doc/Serializer/DataSerializer/DateTimeSerializer.md)
    - [ObjectSerializer](doc/Serializer/DataSerializer/ObjectSerializer.md)
    - [TraversableSerializer](doc/Serializer/DataSerializer/TraversableSerializer.md)
    - [Implementing your own data serializer](doc/Serializer/DataSerializer/YourOwn.md)
- Config loaders (used in `ObjectSerializer`):
    - [SerializerArrayConfigLoader](doc/Config/SerializerArrayConfigLoader.md)
    - [SerializerFilesConfigLoader](doc/Config/SerializerFilesConfigLoader.md)
    - [SerializerDirsConfigLoader](doc/Config/SerializerDirsConfigLoader.md)
    - [Config caching](doc/Config/YourOwn.md)
    - [Implementing your own config loader](doc/Config/YourOwn.md)
- Serializer itself:
    - [Built-in serializer](doc/Serializer/Serializer.md)
    - [Implementing your own serializer](doc/Serializer/YourOwn.md)

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

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://avatars.githubusercontent.com/u/1309356?v=4)[Andrey](/maintainers/Botanick)[@Botanick](https://github.com/Botanick)

---

Top Contributors

[![Botanick](https://avatars.githubusercontent.com/u/1309356?v=4)](https://github.com/Botanick "Botanick (55 commits)")

### Embed Badge

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

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

###  Alternatives

[mck89/peast

Peast is PHP library that generates AST for JavaScript code

19037.7M41](/packages/mck89-peast)[sauladam/shipment-tracker

Parses tracking information for several carriers, like UPS, USPS, DHL and GLS by simply scraping the data. No need for any kind of API access.

9642.0k](/packages/sauladam-shipment-tracker)[jstewmc/rtf

Read and write Rich Text Format (RTF) documents with PHP

46143.1k6](/packages/jstewmc-rtf)[moonshine/layouts-field

Field for repeating groups of fields for MoonShine

107.9k](/packages/moonshine-layouts-field)[tcds-io/php-jackson

A lightweight, flexible object serializer for PHP, inspired by FasterXML/jackson

112.9k10](/packages/tcds-io-php-jackson)

PHPackages © 2026

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