PHPackages                             kapitanluffy/array-legacy - 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. kapitanluffy/array-legacy

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

kapitanluffy/array-legacy
=========================

05PHP

Since Nov 12Pushed 7y ago1 watchersCompare

[ Source](https://github.com/kapitanluffy/array-legacy)[ Packagist](https://packagist.org/packages/kapitanluffy/array-legacy)[ RSS](/packages/kapitanluffy-array-legacy/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

ArrayLegacy
===========

[](#arraylegacy)

A class for converting arrays into fault-tolerant objects. Its aim is to access arrays as usual but without checking if a key is "set".

```
// No more checking if the key is set
if (isset($foo['baz')) {
    $baz = $foo['baz'];
}

// No more setting a default value
if (isset($foo['bar') == false) {
    $foo['bar'] = 'default value';
}
```

#### What are "legacy" arrays?

[](#what-are-legacy-arrays)

These are arrays that are used like objects. After working with "legacy" codes, I have seen many of them use arrays to store data. They (the developers) did not bother creating objects that would "model" their data because there's "not enough time" or "too much refactoring".

With ArrayLegacy, we can avoid this..

> **NOTICE** Undefined index: Foo on line number 5

#### Usage

[](#usage)

Convert an array into an ArrayLegacy

```
$foo = [
    "title" => "FooBar",
    "in_stock" => 1000,
    "price" => 100
];

$foo = ArrayLegacy::make($foo);
```

Use like an array

```
$foo['title'] = "FooBaz";
// Output: FooBaz
echo $foo['title'];
```

Use a getter/setter method

```
$foo->setInStock(999);
// Output: 999
echo $foo->getInStock();
```

Use get/set methods

```
$foo->set("price", 99);
// Output: 99
echo $foo->get("price");
```

With `get()` you can also specify a default value if the key does not exist

```
// Output: This is a default description
echo $foo->get("description", "This is a default description");
```

Remove a key using `unset()`

```
unset($foo["title"]);
// Output: null
echo $foo["title"];
```

Use a mutator when accessing/modifying a key

```
// Note that mutators should directly access `attributes` property
class Foo extends ArrayLegacy {
    public function setTitle($value) {
        $this->attributes['title'] = strtolower($value);
    }

    public function getTitle() {
        return ucwords($this->attributes['title']);
    }
}

$foo = new Foo($foo);
echo $foo->setTitle("This is a test");

// Output: This Is A Test
echo $foo->getTitle();
```

Using PHP array functions

You can use [array functions](https://secure.php.net/manual/en/ref.array.php) by calling it directly in the object.

- Functions with an `array_` prefix can be called without the prefix.
- Functions returning the array type will return a new `ArrayLegacy` instance.
- Functions that pass the array by reference will modify the current instance.

Unsupported functions are the following:

- array\_combine
- array\_fill\_keys
- array\_fill
- range
- list
- extract

```
$foo = new Foo($foo);

// calls array_keys, returns a new ArrayLegacy instance of keys
$foo->keys('bar');

// calls shuffle and applies it to the current instance
$foo->shuffle();
```

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/94708d8e5552d7869dca34196b0fd8785584117b7f3d534abd849ab574da70ab?d=identicon)[kapitanluffy](/maintainers/kapitanluffy)

---

Top Contributors

[![kapitanluffy](https://avatars.githubusercontent.com/u/485799?v=4)](https://github.com/kapitanluffy "kapitanluffy (5 commits)")

---

Tags

arrayslegacy-codephp

### Embed Badge

![Health badge](/badges/kapitanluffy-array-legacy/health.svg)

```
[![Health](https://phpackages.com/badges/kapitanluffy-array-legacy/health.svg)](https://phpackages.com/packages/kapitanluffy-array-legacy)
```

###  Alternatives

[makeabledk/laravel-factory-enhanced

180118.6k4](/packages/makeabledk-laravel-factory-enhanced)[lukeraymonddowning/self-healing-urls

16715.9k](/packages/lukeraymonddowning-self-healing-urls)[yii2mod/yii2-sweet-alert

Alert widget based on SweetAlert extension {@link http://tristanedwards.me/sweetalert)

43154.0k2](/packages/yii2mod-yii2-sweet-alert)[heureka/inflection

Czech inflection library

6163.9k](/packages/heureka-inflection)[ptachoire/php-dmtx

Datamatrix r/w based on libdmtx &lt;http://www.libdmtx.org/&gt;

1868.3k](/packages/ptachoire-php-dmtx)[cybercog/yii2-google-analytics

Google Analytics Widget for the Yii2 framework

1677.1k2](/packages/cybercog-yii2-google-analytics)

PHPackages © 2026

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