Download the PHP package stougeiro/immutable without Composer

On this page you can find all versions of the php package stougeiro/immutable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package immutable

PHP PHPStan-Level Pest-php License

Immutable

Immutable is a rigorously designed data structure for PHP that enforces deep immutability across arrays, objects, and nested collections. It provides a predictable, safe, and expressive way to represent structured data without allowing accidental mutation, dynamic property creation, or silent type inconsistencies. Every value stored inside an Immutable instance is recursively normalized, ensuring that associative arrays become immutable objects, indexed arrays become immutable lists, and scalar values remain untouched. This strict normalization ensures that the structure you create is the structure you keep — permanently.

The core philosophy behind Immutable is to eliminate an entire class of bugs caused by unintended state changes. In traditional PHP arrays and objects, any part of the structure can be modified at any time, often far from where the data was originally created. Immutable prevents this by guaranteeing that once a structure is created, its shape and values cannot be altered — not directly, not indirectly, and not through nested references.

Immutable brings discipline and reliability to PHP’s flexible but mutation‑prone data structures. It enforces deep immutability, provides safe and expressive access patterns, and ensures that your data remains exactly as intended from the moment it is created. Whether used in small utilities or large-scale applications, Immutable helps developers write clearer, safer, and more predictable code.

✨ Features


📦 Installation

Install via Composer:

🚀 Usage Example

Immutable Object Access

This shows object-style access for associative arrays, preserving structure and preventing mutation.

Immutable List Access

Indexed arrays behave as immutable lists, allowing safe index access without converting items into objects.

Deep Conversion Back to Native Arrays

toArray() deeply unwraps the immutable structure into a native PHP array, ensuring the original immutable data remains untouched.

Using Immutable as an API Response Wrapper (REST API)

This ensures your API layer never mutates the response data accidentally.

Using Immutable Inside a DTO (Data Transfer Object)

DTOs are perfect for Immutable because they represent read‑only structured data.

This pattern guarantees that service layers cannot mutate DTO data, preserving integrity across the application.

Using Immutable to Normalize External Service Data (Microservices / Integrations)

Imagine receiving data from a microservice or external provider. Immutable ensures the structure is safe and predictable.

This pattern is extremely useful in microservices, queue consumers, event-driven systems, API gateways or domain boundaries. It prevents accidental mutation of external data.

🔌 Easy Integration

Immutable was designed to fit naturally into any PHP application architecture — from small scripts to full frameworks — without requiring adapters, service providers, or special configuration. Because it behaves like a read‑only data layer, it integrates seamlessly into DTOs, API responses, service layers, and domain logic.

To support predictable return types and stronger system expectations, Immutable provides an ImmutableInterface, allowing developers to type‑hint immutable structures throughout the application. This ensures consistent behavior and prevents accidental mutation at architectural boundaries.

Immutable also includes a dedicated factory method, Immutable::fromArray(), which normalizes any array into a fully immutable structure. For convenience, a global helper function immutable() is available, offering a concise and expressive way to create immutable data wherever needed.


🧠 Why Immutable?

PHP’s dynamic nature makes it easy to accidentally mutate data, especially when passing arrays through multiple layers of an application. A single unintended assignment can corrupt shared state, break assumptions, or introduce subtle bugs that are difficult to trace.

Immutable solves this by enforcing:

It is ideal for:

Design Goals


🤝 Contributions

Contributions are welcome. Feel free to open issues or submit pull requests.



All versions of immutable with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package stougeiro/immutable contains the following files

Loading the files please wait ...