PHPackages                             serafim/immutable - 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. serafim/immutable

Abandoned → [phpfn/immutable](/?search=phpfn%2Fimmutable)ArchivedLibrary[Utility &amp; Helpers](/categories/utility)

serafim/immutable
=================

Simple helper to ensure immutable objects

1.0.0(6y ago)0192MITPHP ^7.2|^8.0

Since Nov 22Pushed 6y agoCompare

[ Source](https://github.com/SerafimArts/Immutable)[ Packagist](https://packagist.org/packages/serafim/immutable)[ Docs](https://github.com/SerafimArts/Immutable)[ RSS](/packages/serafim-immutable/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (5)Versions (2)Used By (0)

Immutable
=========

[](#immutable)

 [![Build Status](https://camo.githubusercontent.com/08741a47b7b9616ecae74b69bc7674a48495d7f711c7965b247f513b9ea88b76/68747470733a2f2f7472617669732d63692e6f72672f5365726166696d417274732f496d6d757461626c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/SerafimArts/Immutable) [![](https://camo.githubusercontent.com/c3c4ac0f55bbab154427df5cdde7f22b56992f1bea103be239ed91035b5ad894/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f62323630366534616130643730333037313938642f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/SerafimArts/Immutable/maintainability) [![](https://camo.githubusercontent.com/625f5dbd1c37819475641b30e272bb760ce69e93771ca396aa3d16d1040f55c6/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f62323630366534616130643730333037313938642f746573745f636f766572616765)](https://codeclimate.com/github/SerafimArts/Immutable/test_coverage)

 [![PHP 7.1+](https://camo.githubusercontent.com/148daf46be94cc99b1f8ca97ab898c4bcf659eecb12fa0e02eda61d5533485be/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d372e322b2d3466356239332e737667)](https://packagist.org/packages/serafim/immutable) [![Latest Stable Version](https://camo.githubusercontent.com/48fc1d7994950b1e8c32c9a96db94d72460ae77dcb9bf9c80ef4adccff4a3595/68747470733a2f2f706f7365722e707567782e6f72672f7365726166696d2f696d6d757461626c652f76657273696f6e)](https://packagist.org/packages/serafim/immutable) [![Total Downloads](https://camo.githubusercontent.com/fa6ccf92ab7f4bcebbfa81ec665dea62f05d6f3c83b28a6aba216a1bb8e6bfe7/68747470733a2f2f706f7365722e707567782e6f72672f7365726166696d2f696d6d757461626c652f646f776e6c6f616473)](https://packagist.org/packages/serafim/immutable) [![License MIT](https://camo.githubusercontent.com/4e7c0ecbaf18b64f740c77c08ae2987bd7e7b88159b29c6c9964d576f7b48e57/68747470733a2f2f706f7365722e707567782e6f72672f7365726166696d2f696d6d757461626c652f6c6963656e7365)](https://raw.githubusercontent.com/SerafimArts/Immutable/master/LICENSE.md)

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

[](#installation)

Install via [Composer](https://getcomposer.org/):

```
composer require serafim/immutable
```

Usage
-----

[](#usage)

To ensure immunity of objects, you just need to wrap any code of your method in a closure.

Mutable object example:

```
class Example
{
    private int $value = 42;

    public function update(int $newValue): self
    {
        $this->value = $newValue;

        return $this;
    }
}
```

Making it immutable:

```
class Example
{
    private int $value = 42;

    // Sample #1 (PHP 7.4+)
    public function with(int $newValue): self
    {
        return immutable(fn () => $this->value = $newValue);
    }

    // Sample #2 (PHP 7.3 and below)
    public function with(int $newValue): self
    {
        return immutable(function (): void { $this->value = $newValue; });
    }

}
```

That`s all!

Features
--------

[](#features)

- ☑ Full PHP 7.2, PHP 7.3, PHP 7.4 and PHP 8.0 (dev) compatibility ([proof](https://travis-ci.org/SerafimArts/Immutable))
- ☑ [PSR-4](https://www.php-fig.org/psr/psr-4/)
- ☑ [PSR-12](https://www.php-fig.org/psr/psr-12/)
- ☑ Convenient helpers that don't break code =)
- ☑ Feel the power of immutable objects!

License
-------

[](#license)

See [LICENSE](https://github.com/SerafimArts/Immutable/master/LICENSE.md)

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity62

Established project with proven stability

 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

Unknown

Total

1

Last Release

2369d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/150420?v=4)[Ruslan Sharipov](/maintainers/Serafim)[@serafim](https://github.com/serafim)

---

Top Contributors

[![SerafimArts](https://avatars.githubusercontent.com/u/2461257?v=4)](https://github.com/SerafimArts "SerafimArts (9 commits)")

---

Tags

functionalimmutablestatelesssugar

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/serafim-immutable/health.svg)

```
[![Health](https://phpackages.com/badges/serafim-immutable/health.svg)](https://phpackages.com/packages/serafim-immutable)
```

###  Alternatives

[lstrojny/functional-php

Functional primitives for PHP

2.0k7.3M48](/packages/lstrojny-functional-php)[nikic/iter

Iteration primitives using generators

1.1k5.9M38](/packages/nikic-iter)[qaribou/immutable.php

Immutable, highly-performant collections, well-suited for functional programming and memory-intensive applications.

344146.0k](/packages/qaribou-immutablephp)[aeon-php/calendar

PHP type safe, immutable calendar library

2079.7M16](/packages/aeon-php-calendar)[lambdish/phunctional

λ PHP functional library

3612.0M23](/packages/lambdish-phunctional)[crell/fp

Functional utilities for PHP 8 and later

91429.8k11](/packages/crell-fp)

PHPackages © 2026

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