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

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

phauthentic/attribute-serializer
================================

10PHP

Since Feb 25Pushed 2y ago1 watchersCompare

[ Source](https://github.com/Phauthentic/attribute-serializer)[ Packagist](https://packagist.org/packages/phauthentic/attribute-serializer)[ RSS](/packages/phauthentic-attribute-serializer/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Attribute Based Serializer
==========================

[](#attribute-based-serializer)

[![PHP >= 8.1](https://camo.githubusercontent.com/4fa3809f87c8fee607369cc77dc064d826616d28eb87b045ff834d3dbae99119/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d504850266d6573736167653d253545382e3126636f6c6f723d373837434235267374796c653d666f722d7468652d6261646765266c6f676f3d706870)](https://camo.githubusercontent.com/4fa3809f87c8fee607369cc77dc064d826616d28eb87b045ff834d3dbae99119/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d504850266d6573736167653d253545382e3126636f6c6f723d373837434235267374796c653d666f722d7468652d6261646765266c6f676f3d706870)[![phpstan Level 8](https://camo.githubusercontent.com/12b6b9438b73c95050b7fc8811f082842fb9d1ec678d3bf802ead8a4b859440c/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d7068707374616e266d6573736167653d4c6576656c2532303826636f6c6f723d253343434f4c4f52253345267374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/12b6b9438b73c95050b7fc8811f082842fb9d1ec678d3bf802ead8a4b859440c/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d7068707374616e266d6573736167653d4c6576656c2532303826636f6c6f723d253343434f4c4f52253345267374796c653d666f722d7468652d6261646765)[![License: MIT](https://camo.githubusercontent.com/d1f48776f80be8eba6920f4e65d7c4b7d1d13bbc6b779d56ca1ecc08181cd2be/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d4c6963656e7365266d6573736167653d4d495426636f6c6f723d253343434f4c4f52253345267374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/d1f48776f80be8eba6920f4e65d7c4b7d1d13bbc6b779d56ca1ecc08181cd2be/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d4c6963656e7365266d6573736167653d4d495426636f6c6f723d253343434f4c4f52253345267374796c653d666f722d7468652d6261646765)

Serializer class for extracting data from objects annotated with the `#[Serialize]` attribute.

This class provides a method, serialize, to transform an object into an associative array by extracting data from its properties and constants based on the `#[Serialize]` attribute.

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

[](#installation)

```
composer require phauthentic/attribute-serializer
```

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

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

Add the `#[Serialize()]` attribute to the property or constant. You can rename the property in the resulting array by providing a name to the attribute `#[Serialize('other-name')]`.

```
class Example {
    #[Serialize('username')]
    private $name = 'serializer';
}

var_dump((new Serializer())->serialize(new Example()));
```

```
[
    'username' => 'serializer'
]

```

### Dot notation for deep arrays

[](#dot-notation-for-deep-arrays)

Field names can be dynamically renamed, even into deeper array structures, by using the dot notation.

```
class Example2 {
    #[Serialize('first.second')]
    private $name = 'serializer';
}

var_dump((new Serializer())->serialize(new Example2());
```

```
[
    'first' => [
        'second' => 'serializer'
    ]
]

```

### ToArrayTrait

[](#toarraytrait)

```
class Example3 {
    use ToArrayTrait;

    #[Serialize('username')]
    private $name = 'serializer';
}

var_dump((new Example3)->toArray());
```

```
[
    'username' => 'serializer'
]

```

License
-------

[](#license)

Copyright Florian Krämer

Licensed under the [MIT license](LICENSE).

###  Health Score

12

—

LowBetter than 0% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity19

Early-stage or recently created project

 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/0643e6255da841fe65260ec6e263d8908a40a84b884c32e9fc6be6a15e252fa8?d=identicon)[burzum](/maintainers/burzum)

---

Top Contributors

[![floriankraemer](https://avatars.githubusercontent.com/u/4996022?v=4)](https://github.com/floriankraemer "floriankraemer (1 commits)")

---

Tags

attributesphp8serializationserializersolid-principles

### Embed Badge

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

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

###  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)
