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

ActiveLibrary

northern/serializer
===================

Serializes a annotated object to a plain PHP array.

1.0.1(11y ago)020MITPHPPHP &gt;=5.3.0

Since Jul 26Pushed 11y ago1 watchersCompare

[ Source](https://github.com/northern/Serializer)[ Packagist](https://packagist.org/packages/northern/serializer)[ Docs](http://github.com/northern/Serializer)[ RSS](/packages/northern-serializer/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (3)Versions (4)Used By (0)

Serializer
==========

[](#serializer)

Northern\\Serializer is a small PHP library that allows you to annotate your POPO's and serialize them into a plain PHP array.

To run the tests:

```
vendor/bin/phpunit

```

To generate code coverage reports:

```
vendor/bin/phpunit --coverage-html ./reports

```

Find Northern\\Serializer on [Packagist](https://packagist.org/packages/northern/serializer)

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

[](#installation)

Install through Composer.

```
"require": {
  "northern/serializer": "1.*"
}
```

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

[](#how-to-use)

To use Northern\\Serializer you need to import it:

```
use Northern\Serializer\Serializer;
```

You can now instantiate and run the serializer on any PHP object:

```
$serializer = new Serializer();

$array = $serializer->toArray( $someObject );
```

However, without having annotated `$someObject`'s class, nothing will be serialized. Let's annotate the class of which `$someObject` is an instance:

```
use Northern\Serializer\Annotation as Serialize;

class SomeClass {

  /** @Serialize\Int */
  protected $myProperty = 123;

}
```

We have now annotated our class and indicated that the `$myProperty` attribute must be serialized as an integer. When we now serialize `$someObject` (which is assumed to be an instance of `SomeClass`) the `$array` variable will contain the serialized data:

```
Array(
  [myProperty] => 123
)
```

Easy as.

With Northern\\Serializer you can also serialize methods. Usually a serialized method is a getter of some sort. Let's look at an example:

```
use Northern\Serializer\Annotation as Serialize;

class SomeClass {

  /** @Serialize\Int(name="myValue") */
  public function getMyValue()
  {
    return 123;
  }

}
```

As the above demonstrates, by simply adding the correct annotation to the method, the output of the method will be serialized as the key set by the annotation `name` parameter, which is `myValue` in our example:

```
Array(
  [myValue] => 123
)
```

If the `name` attribute is not specified on the annotation then the name of the method will be used as the serialization key, e.g:

```
class SomeClass {

  /** @Serialize\Bool */
  public function isValid()
  {
    return true;
  }

}
```

Which will produce:

```
Array(
  [isValid] => 1
)
```

Serializing properties and methods are of course very handy but what about a nested object? Can do too:

```
class BarClass {

	/** @Serialize\Int */
	protected $barValue = 123;

}

class FooClass {

  /** @Serialize\Object */
  protected $bar;

  public function __construct()
  {
    $this->bar = new BarClass();
  }

}
```

Notice the `Serialize\Object` annotation? Be careful with recursive references!

Reference
---------

[](#reference)

These are the available serialization types:

Type | Description

- | - `Serialize\Bool` | Serializes a boolean value. `Serialize\Int` | Serializes an integer value. `Serialize\Object` | Serializes an object. Indicates recursion. `Serialize\Collection` | Serializes an iterable, e.g. an array of objects.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

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

Total

2

Last Release

4314d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/547843?v=4)[Luke Schreur](/maintainers/northern)[@northern](https://github.com/northern)

---

Top Contributors

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

---

Tags

dataserializetransform

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[fakerphp/faker

Faker is a PHP library that generates fake data for you.

3.9k358.5M3.5k](/packages/fakerphp-faker)[symfony/var-exporter

Provides tools to export, instantiate, hydrate, clone and lazy-load PHP objects

2.1k378.1M441](/packages/symfony-var-exporter)[amphp/serialization

Serialization tools for IPC and data storage in PHP.

13451.1M18](/packages/amphp-serialization)[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11320.2M21](/packages/anourvalar-eloquent-serialize)[marquine/php-etl

Extract, Transform and Load data using PHP.

182137.5k](/packages/marquine-php-etl)[wizaplace/php-etl

Extract, Transform and Load data using this PHP written migration library.

7598.9k1](/packages/wizaplace-php-etl)

PHPackages © 2026

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