PHPackages                             sebvie/php-object-history - 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. sebvie/php-object-history

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

sebvie/php-object-history
=========================

Record the change of a PHP object and display it in a csv file

v1.0.1(6y ago)1565↓75%mitPHPPHP &gt;=7.0

Since Oct 17Pushed 6y ago2 watchersCompare

[ Source](https://github.com/sebvie/php-object-history)[ Packagist](https://packagist.org/packages/sebvie/php-object-history)[ Docs](https://github.com/sebvie/php-object-history)[ RSS](/packages/sebvie-php-object-history/feed)WikiDiscussions master Synced 3d ago

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

[![Build Status](https://camo.githubusercontent.com/34d357f0ae1281e07ac401f1641f151b34b459b79696523850a964d1517f6b2e/68747470733a2f2f7472617669732d63692e6f72672f7365627669652f7068702d6f626a6563742d686973746f72792e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/sebvie/php-object-history)[![Coverage Status](https://camo.githubusercontent.com/91fe8db4ccc9a50a25bb1accd44c4ad98dc4baefec1e2dd59af2414b3c0e4d80/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f7365627669652f7068702d6f626a6563742d686973746f72792f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/sebvie/php-object-history?branch=master)[![codecov](https://camo.githubusercontent.com/87b954ae37b30072442bd36c752149b7b59aa68ae54ef00875b7f5bcfb8ece67/68747470733a2f2f636f6465636f762e696f2f67682f7365627669652f7068702d6f626a6563742d686973746f72792f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/sebvie/php-object-history)

php-object-history
==================

[](#php-object-history)

The package records changes of a PHP object and persists it to a storage. This can be useful if you have a stream of data and you only want the get the change set and throw away the other data to reduce memory usage.

Installation:
-------------

[](#installation)

```
composer require sebvie/php-object-history

```

Example:
--------

[](#example)

Inititate Storage and Comparer:

```
use PhpObjectHistory\Comparer\ObjectComparer;
use PhpObjectHistory\Storage\CsvFileStorage;
use PhpObjectHistory\ObjectHistory;

$storage = new CsvFileStorage();
$storage->setCsvFilePath($filePath);

$objectComparer = new ObjectComparer();

$objectHistory = new ObjectHistory(
    $storage,
    $objectComparer
);

```

Add objects:

```

$object = new \stdClass();
$object->testProperty = 1;
$object->testPropertyUnchanged = true;

$objectHistory->addObject($object);

$object = new \stdClass();
$object->testProperty = 2;
$object->testPropertyUnchanged = true;

$objectHistory->addObject($object);

```

Result is csv file containing:

```
testProperty,testPropertyUnchanged
1;true
2

```

Custom Formatters
-----------------

[](#custom-formatters)

You can add custom Formatters to flatten your object:

```
use PhpObjectHistory\Formatter\ObjectFormatterInterface

class ToStringFormatter implements ObjectFormatterInterface
{

    /**
     * @param object $object
     * @return string
     */
    public function format(object $object): string
    {
        return $object->__toString();
    }

    /**
     * @param object $object
     * @return bool
     */
    public function supports(object $object): bool
    {
        return method_exists($object, '__toString');
    }
}

```

add the formatter:

```
$formatter = new CustomFormatter();

$storage = new CsvFileStorage();
$storage->setCsvFilePath($filePath);
$storage->getObjectFormatterHandler()->addFormatter($formatter);

$objectComparer = new ObjectComparer();
$objectComparer->getObjectFormatterHandler()->addFormatter($formatter);

```

Implement custom Storages
-------------------------

[](#implement-custom-storages)

```
use PhpObjectHistory\Entity\ObjectChange;

class InMemoryStorage implements StorageInterface
{

    /**
     * @var array
     */
    protected $result = [];

    /**
     * @param object $object
     */
    public function setInitialObject(object $object): void
    {
        $this->result[] = $object;
    }

    /**
     * @param ObjectChange[] $objectChanges
     */
    public function addObjectChanges(array $objectChanges): void
    {
        if (empty($objectChanges)) {
            return;
        }

        $this->result[] = $objectChanges;
    }

    /**
     * @return array
     */
    public function getResult(): array
    {
        return $this->result;
    }

}

```

Available Storage
-----------------

[](#available-storage)

- CsvFileStorage
- InMemoryStorage

Available Formatters
--------------------

[](#available-formatters)

- DatetimeFormatter
- ToStringFormatter

ignore object properties
------------------------

[](#ignore-object-properties)

You can ignore changes of certian properties. This will not trigger an object change.

This is useful when you have properties like timestamps which always change but can be ignored.

```
$ignoreAttributes = ['boolProperty'];
$objectComparer = new ObjectComparer();
$objectComparer->setIgnoreAttributes($ignoreAttributes);

```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

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

Total

2

Last Release

2373d ago

PHP version history (2 changes)v1.0PHP ^7.2

v1.0.1PHP &gt;=7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/475e4dd1b7882bdf983cdeebdcebb31f1b90ef5e9b6c41f275c5031b1be63ea0?d=identicon)[sebvie](/maintainers/sebvie)

---

Top Contributors

[![sebvie](https://avatars.githubusercontent.com/u/32967815?v=4)](https://github.com/sebvie "sebvie (38 commits)")

---

Tags

objecthistory

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sebvie-php-object-history/health.svg)

```
[![Health](https://phpackages.com/badges/sebvie-php-object-history/health.svg)](https://phpackages.com/packages/sebvie-php-object-history)
```

###  Alternatives

[myclabs/deep-copy

Create deep copies (clones) of your objects

8.9k849.8M169](/packages/myclabs-deep-copy)[symfony/property-access

Provides functions to read and write from/to an object or array using a simple string notation

2.8k295.3M2.5k](/packages/symfony-property-access)[cuyz/valinor

Dependency free PHP library that helps to map any input into a strongly-typed structure.

1.5k9.2M108](/packages/cuyz-valinor)[marcocesarato/php-conventional-changelog

Generate changelogs and release notes from a project's commit messages and metadata and automate versioning with semver.org and conventionalcommits.org

2511.3M109](/packages/marcocesarato-php-conventional-changelog)[yzen.dev/plain-to-class

Class-transformer to transform your dataset into a structured object

16293.9k6](/packages/yzendev-plain-to-class)[jasny/dotkey

Dot notation access for objects and arrays

14219.5k6](/packages/jasny-dotkey)

PHPackages © 2026

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