Immutable lists

Learn about the immutable-lists data structure in PHP.

What are immutable lists?

An immutable list is a persistent data structure. That is, it’s a data structure that maintains its previous version whenever it’s modified. An immutable list always yields an updated version of itself. It’s possible to view an immutable list as an upgrade of constants, which don’t have the properties of persistent structures.

PHP libraries supporting immutable lists

There exists multiple libraries in PHP capable of enabling the creation of immutable lists. Among the packages with such capability are the immutable-php and phunkie libraries.

The immutable-php package

The command below demonstrates the installation of the immutable-php package.

composer require quaribou/immutable.php

The code below demonstrates the usage of the installed package.

Get hands-on with 1400+ tech skills courses.