PHPackages                             robertlabrie/robertserializer - 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. robertlabrie/robertserializer

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

robertlabrie/robertserializer
=============================

My serializer

024PHP

Since Oct 25Pushed 10y ago1 watchersCompare

[ Source](https://github.com/robertlabrie/robertserializer)[ Packagist](https://packagist.org/packages/robertlabrie/robertserializer)[ RSS](/packages/robertlabrie-robertserializer/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

robertserializer
================

[](#robertserializer)

Why
---

[](#why)

RobertSerializer was born out of the desire to easily store objects in MongoDB. The existing PHP serializer is fine for storing in session, but is useless for a document DB. When I asked around, the consensus seemed to be using something called an "ODM (Object Document Model)" which is essentially a property map between the Mongo document and my PHP class. I didn't feel like maintaining one of those! So, RobertSerializer is what I came up with.

How it works
------------

[](#how-it-works)

I leverage PHPs' reflection class to recursively crawl the input object properties and feed the data back out as an array. Mongo likes arrays, so that's why it's an array, but you could easily called `json_encode()` on it and store it in RavenDB if that's your thing.

### What's the catch?

[](#whats-the-catch)

I need to know your objects type when I deserialize later, so I add an extra element to the array `__TYPE__`(you can change it). For this reason, it's a good idea to use namespaces. Also, probably if you change your class namespace, you won't be able to deserialize an object. If anyone uses this and that's a problem, we'll let you define a map (boo!) so that you can survive a refactoring.

### Why a special field?

[](#why-a-special-field)

BSON seemed ugly

How to use it
-------------

[](#how-to-use-it)

`composer require RobertSerializer`

```
#do the necessary composer bits
$rs = new \RobertSerializer\RobertSerializer();
$in = new \Example\Foo();
$ser = $rs->serialize($in);
//$ser is an array that you can pass around

$out = $rs->deserialize($ser);
//$out is an instance of Foo(), exactly how you remember it!
```

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

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/adca28ce3a217da91ee01061cb9a79e1df02fabd37bd22cf53fe8ad5b7c19104?d=identicon)[robertlabrie](/maintainers/robertlabrie)

---

Top Contributors

[![robertlabrie](https://avatars.githubusercontent.com/u/4543717?v=4)](https://github.com/robertlabrie "robertlabrie (8 commits)")

### Embed Badge

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

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

###  Alternatives

[mck89/peast

Peast is PHP library that generates AST for JavaScript code

19139.2M47](/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.

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

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

45153.1k6](/packages/jstewmc-rtf)[tcds-io/php-jackson

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

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

PHPackages © 2026

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