PHPackages                             niko9911/serializable-entity - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. niko9911/serializable-entity

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

niko9911/serializable-entity
============================

Convert entity into array or json. Apply JsonSerializable into entity.

1.1.0(6y ago)394MITPHPPHP ^7.2

Since Mar 1Pushed 6y ago1 watchersCompare

[ Source](https://github.com/NikoGrano/php-serializable-entity)[ Packagist](https://packagist.org/packages/niko9911/serializable-entity)[ RSS](/packages/niko9911-serializable-entity/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (2)Versions (7)Used By (0)

Serializable Entity
===================

[](#serializable-entity)

Convert entity into array or json. Apply JsonSerializable into entity by extending a class.

See my blog post about this [here](https://xn--gran-8qa.fi/serializing-php-entities-to-json/)!

Install
-------

[](#install)

Via [composer](http://getcomposer.org):

```
composer require niko9911/serializable-entity
```

Usage
-----

[](#usage)

You can use this to convert objects statically.

`EntityToArray::convert(object $entity ,[, int $recursionDepth = 2  [, bool $throwExceptionOnRecursionLimit = true ]  [, bool $replaceValuesOnRecursionLimit = true ]]]): array`

Or if you want benefit from implementing \\JsonSerializable interface you can extend class \\Niko9911\\Serializable\\Serializable. In that case you will have 3 new methods in your class, `toArray, toJson and jsonSerialize`.

### Example: Using Static Way

[](#example-using-static-way)

```
