PHPackages                             vlx/php-immutable-tools - 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. vlx/php-immutable-tools

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

vlx/php-immutable-tools
=======================

Tools for work with immutable data objects

0.2.0(1y ago)08MITPHPPHP &gt;=8.0

Since Sep 17Pushed 1y ago1 watchersCompare

[ Source](https://github.com/igrizzli/php-immutable-tools)[ Packagist](https://packagist.org/packages/vlx/php-immutable-tools)[ RSS](/packages/vlx-php-immutable-tools/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (4)Used By (0)

To make it possible to create a modified copy of an immutable object use trait, and call method `with`.

```
readonly class SomeData
{
    use ImmutableData;

    public function __construct(
        public int $field,
        public AnotherData $objectField,
        public bool $flag = false,
    ) {
    }
}

$object = new SomeData(field: 1, objectField: new AnotherData(), flag: true);
$newObject = $object->with(field: 2, flag: false);
```

You can also use rector for automatic generation phpDoc for `with` method in each class which use `ImmutableData`

```
