PHPackages                             whateverthing/captain-cold - 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. whateverthing/captain-cold

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

whateverthing/captain-cold
==========================

An array that can be frozen (turned to readonly)

v1.0.0(2y ago)13MITPHP

Since Sep 30Pushed 2y ago1 watchersCompare

[ Source](https://github.com/beryllium/captain-cold)[ Packagist](https://packagist.org/packages/whateverthing/captain-cold)[ RSS](/packages/whateverthing-captain-cold/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Captain Cold
============

[](#captain-cold)

PHP has arrays. PHP has readonly properties. PHP does not have the ability to take a non-readonly array and flip it to readonly.

This library aims to fix that exceedingly rare edge case.

Inspiration
-----------

[](#inspiration)

I saw a Mastodon post where someone claimed that Lua table expressions are superior to JSON in every possible way. But when I looked into it, it seemed to me that Lua table expressions are not so different from PHP tables. They both seem to mix together the concepts of arrays and dictionaries and so forth.

Except, Lua tables have a `.freeze()` option. PHP doesn't have that.

So I decided to create a silly userland implementation of my own to see if it might offer some value.

And while my first instinct was to name it after Mister Freeze, and my second idea was to name it after Nora Fries (aka Mrs Freeze), I decided to name it after Captain Cold instead. Yet another ice-themed DC villain.

If it turns out to provide some value to someone, I might rename the project to `Whateverthing\Freezable`.

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

[](#installation)

```
composer require whateverthing/captain-cold

```

Usage
-----

[](#usage)

Passing an array into the `FreezableArray` constructor will create an array-accessible object that you can freeze at your leisure.

### FreezableArray

[](#freezablearray)

Example:

```
$array = ['one', 'two', 'three'];
$freezableArray = new \Whateverthing\CaptainCold\FreezableArray($array);
```

You can then call `->freeze()` to lock the array down:

```
$freezableArray->freeze();
$freezableArray[] = 'four'; // Fatal error: Cannot modify readonly property
```

### FrozenArray

[](#frozenarray)

A `FrozenArray` object is, and will always be, immutable from the moment it is constructed.

```
$array = ['one', 'two', 'three'];
$freezableArray = new \Whateverthing\CaptainCold\FrozenArray($array);

$freezableArray[] = 'four'; // Fatal error: Cannot modify readonly property
```

### ThawableArray

[](#thawablearray)

The `ThawableArray` class deals with immutability the same way as other immutable objects do: by getting a fresh object.

```
$array = ['one', 'two', 'three'];
$thawableArray = new \Whateverthing\CaptainCold\ThawableArray($array);
$thawableArray->freeze();

$thawableArray[] = 'four'; // Fatal error: Cannot modify readonly property

$thawedArray = $thawableArray->thaw();

$thawedArray[] = 'four'; // Works!

// However, if you freeze it again, it becomes immutable.
$thawedArray->freeze();
$thawedArray[] = 'five'; // Fatal error: Cannot modify readonly property
```

One quirk of `ThawableArray` is that if the original array has not yet been frozen, a call to `->thaw()` will return `$this`. This can lead to some odd behaviour.

```
$array = ['one', 'two', 'three'];
$thawableArray = new \Whateverthing\CaptainCold\ThawableArray($array);
$thawedArray = $thawableArray->thaw();

$thawedArray[] = 'four'; // Works!

// However, if you freeze it again, it becomes immutable.
$thawedArray->freeze();
$thawedArray[] = 'five'; // Fatal error: Cannot modify readonly property

// But look, the original array has also become frozen!
$thawableArray[] = 'five';  // Fatal error: Cannot modify readonly property
```

Currently, this behaviour is intentional. However, the more I think about it, the more I feel it is too confusing/dangerous.

Contributing
------------

[](#contributing)

Contributions are welcome, but please be aware that I am not the most responsive person on the planet. If something seems to languish, that probably means I need to get pinged again in order to discover or rediscover that it exists.

If you have ideas for improvement, let's discuss it in the issues or on Mastodon, where I can be reached at:

 (@).

I'm particularly interested in hearing if the idea ever helps anyone.

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 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

960d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/602491?v=4)[Kevin Boyd](/maintainers/beryllium)[@beryllium](https://github.com/beryllium)

---

Top Contributors

[![beryllium](https://avatars.githubusercontent.com/u/602491?v=4)](https://github.com/beryllium "beryllium (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/whateverthing-captain-cold/health.svg)

```
[![Health](https://phpackages.com/badges/whateverthing-captain-cold/health.svg)](https://phpackages.com/packages/whateverthing-captain-cold)
```

PHPackages © 2026

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