PHPackages                             harm-less/php-encoder - 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. harm-less/php-encoder

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

harm-less/php-encoder
=====================

Encoder to intelligently convert an entire PHP object to Json or XML e.g.

0.3.0(10y ago)138MITPHPPHP &gt;=5.3.0

Since Feb 7Pushed 10y ago2 watchersCompare

[ Source](https://github.com/harm-less/php-encoder)[ Packagist](https://packagist.org/packages/harm-less/php-encoder)[ Docs](https://github.com/harm-less/php-encoder)[ RSS](/packages/harm-less-php-encoder/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (9)Dependencies (3)Versions (11)Used By (0)

php-encoder
===========

[](#php-encoder)

[![Build Status](https://camo.githubusercontent.com/643eb13b3c6d4ec09615ac75c23f2f4bfd7369321802c1d67d6fe9361225a5aa/68747470733a2f2f7472617669732d63692e6f72672f6861726d2d6c6573732f7068702d656e636f6465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/harm-less/php-encoder)

**php-encoder** is a fast &amp; flexible encoder for PHP 5.3+

About
-----

[](#about)

This library will allow you to save a snapshot of your PHP object in various formats like XML or JSON (encoding). When your project has been setup properly you can reuse the snapshot by decoding it. The decoding process will return the same PHP object you started with.

This library is useful for you if you want to quickly find a way to save a state of your PHP object. Think about a configurator that allows you to customize a certain product in various ways for example.

Getting started
---------------

[](#getting-started)

1. PHP 5.3.x is required
2. Install php-encoder using [Composer](#composer-installation) (recommended) or manually
3. Set up the nodes you need for your PHP objects

Composer Installation
---------------------

[](#composer-installation)

1. Get [Composer](http://getcomposer.org/)
2. Require the encoder with `composer require harm-less/php-encoder`
3. Add the following to your application's main PHP file: `require 'vendor/autoload.php';`

Included encoders
-----------------

[](#included-encoders)

There are currently 2 encoding types available: *XML* and *JSON*. Both can be used interchangeably as long as you have set up your nodes correctly.

Example
-------

[](#example)

*Hello World* - Obligatory hello world example

```

 *
 *
 *
 */
echo htmlentities($encodedResultXml->saveXML());

// decode the XML again
$decoded = $encoder->decode($encodedResultXml->saveXML());

// will output:
/*
 * HelloWorld Object
 * (
 *   [foo:HelloWorld:private] => hello world
 * )
 */
print_r($decoded['hello-world']);
?>
```

Unit Testing
------------

[](#unit-testing)

This project uses [PHPUnit](https://github.com/sebastianbergmann/phpunit/) as its unit testing framework.

The tests all live in `/tests` and each test extends an abstract class `AbstractPETest`

To test the project, simply run `composer install --dev` to download a common version of PHPUnit with composer and run the tests from the main directory with `phpunit` or `./vendor/bin/phpunit`

Contributors
------------

[](#contributors)

- [Harm van der Werf](https://github.com/harm-less)

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity54

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.

###  Release Activity

Cadence

Every ~10 days

Recently: every ~0 days

Total

10

Last Release

3653d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/42dce4ce555f5ff3b3c59e2782bee89c6a6b3663f9b2cb19adad981ca3544e54?d=identicon)[harm-less](/maintainers/harm-less)

---

Top Contributors

[![harm-less](https://avatars.githubusercontent.com/u/6368074?v=4)](https://github.com/harm-less "harm-less (79 commits)")

---

Tags

phpjsonxmlencodingconversionobjectencodedecodedecodingobject conversion

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/harm-less-php-encoder/health.svg)

```
[![Health](https://phpackages.com/badges/harm-less-php-encoder/health.svg)](https://phpackages.com/packages/harm-less-php-encoder)
```

###  Alternatives

[kherge/json

Encodes, decodes, and validates JSON data.

61226.6k6](/packages/kherge-json)[m1/vars

Vars is a simple to use and easily extendable configuration loader with in built loaders for ini, json, PHP, toml, XML and yaml/yml file types. It also comes with in built support for Silex and more frameworks to come soon.

69124.2k1](/packages/m1-vars)

PHPackages © 2026

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