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

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

codelicia/immutable
===================

Enforces immutability on initialized properties of any PHP object

00[2 issues](https://github.com/codelicia/immutable/issues)[1 PRs](https://github.com/codelicia/immutable/pulls)PHP

Since Nov 21Pushed 4y ago4 watchersCompare

[ Source](https://github.com/codelicia/immutable)[ Packagist](https://packagist.org/packages/codelicia/immutable)[ RSS](/packages/codelicia-immutable/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (3)Used By (0)

Codelicia\\Immutable
====================

[](#codeliciaimmutable)

[![Build Status](https://camo.githubusercontent.com/401cf5dd8078e4dc4d68cff783b147db5334f2e973d92dcc38015abdf6044370/68747470733a2f2f7472617669732d63692e636f6d2f636f64656c696369612f696d6d757461626c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/codelicia/immutable)

> Since the [PHP RFC: Readonly properties 2.0](https://wiki.php.net/rfc/readonly_properties_v2)will be available on PHP 8.1 this repository will be archived.

It enforces immutability on initialized properties.

Immutable properties can be really handful to avoid `getter/setter` boiler-plate or just enforce immutability for specific objects.

We see it as specially useful for the following use cases: **VOs**, **DTOs**, **Commands**, **Events** and **ViewModels**.

### Installation

[](#installation)

```
$ composer require codelicia/immutable

```

### Usage

[](#usage)

Enable immutability on your classes just by plugging the `ImmutableProperties` trait on it.

```
final class User
{
    use \Codelicia\ImmutableProperties;

    public string $name;
    public int $age;
}

$user       = new User;
$user->name = "@malukenho";

// this will crash
$user->name = "Throws exception as the property name cannot be reassigned";
```

We recommend you create a `__construct` to make the object stay in a valid state right after the instantiation of it, but it is up to you and your necessity.

```
final class User
{
    use \Codelicia\ImmutableProperties;

    // It is fine to leave the properties visibility as public as the `ImmutableProperties`
    // trait will not allow it to change after it is being initialized in the
    // class constructor
    public string $name;
    public int $age;

    public function __construct(string $name, int $age)
    {
        $this->init(); // The `init()` method must be called here

        $this->name = $name;
        $this->age = $age;
    }
}
```

### Authors

[](#authors)

- Jefersson Nathan ([@malukenho](https://github.com/malukenho))

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

Top contributor holds 83.3% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/7140a8c7b834b07674c6bd74d6cb75792522ceba17dfb1f347489083a0ba1c48?d=identicon)[malukenho](/maintainers/malukenho)

---

Top Contributors

[![malukenho](https://avatars.githubusercontent.com/u/3275172?v=4)](https://github.com/malukenho "malukenho (40 commits)")[![EHER](https://avatars.githubusercontent.com/u/398034?v=4)](https://github.com/EHER "EHER (8 commits)")

### Embed Badge

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

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

###  Alternatives

[components/mathjs

Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with a large set of built-in functions and constants, and offers an integrated solution to work with different data types like numbers, big numbers, complex numbers, fractions, units, and matrices.

15.0k3.8k](/packages/components-mathjs)[koenhendriks/laravel-str-acronym

A package to be able to generate acronyms from strings in Laravel projects using the Str helper and supports the Stringable class.

4352.9k](/packages/koenhendriks-laravel-str-acronym)[njxqlus/filament-lightbox

Lightbox entry for Filament

2054.6k](/packages/njxqlus-filament-lightbox)

PHPackages © 2026

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