PHPackages                             code-distortion/array-object-extended - 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. code-distortion/array-object-extended

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

code-distortion/array-object-extended
=====================================

ArrayObjectExtended class which adds methods missing from PHP's ArrayObject

0.1.2(5mo ago)07481MITPHPPHP 8.2.\* | 8.3.\* | 8.4.\* | 8.5.\*CI passing

Since Dec 30Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/code-distortion/array-object-extended)[ Packagist](https://packagist.org/packages/code-distortion/array-object-extended)[ Docs](https://github.com/code-distortion/array-object-extended)[ RSS](/packages/code-distortion-array-object-extended/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (5)Versions (4)Used By (1)

ArrayObjectExtended
===================

[](#arrayobjectextended)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ed5d24034d18b52282ff87cfe900e77ba1748bd4e188d752dc94449496c730c4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636f64652d646973746f7274696f6e2f61727261792d6f626a6563742d657874656e6465642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/code-distortion/array-object-extended)[![PHP Version](https://camo.githubusercontent.com/c69a8fbaf3bad3826b8c7d0be9a915095d5aa1cb15a2e31d2c331050b442ef6b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e32253230746f253230382e352d626c75653f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/c69a8fbaf3bad3826b8c7d0be9a915095d5aa1cb15a2e31d2c331050b442ef6b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e32253230746f253230382e352d626c75653f7374796c653d666c61742d737175617265)[![GitHub Workflow Status](https://camo.githubusercontent.com/a946df3ed0ed3b9928cb1ce76f53f93daa5b9bc69c9ab4fd2f9b40116fb02c1a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f636f64652d646973746f7274696f6e2f61727261792d6f626a6563742d657874656e6465642f72756e2d74657374732e796d6c3f6272616e63683d6d61696e267374796c653d666c61742d737175617265)](https://github.com/code-distortion/array-object-extended/actions)[![Buy The World a Tree](https://camo.githubusercontent.com/dc3f77a9b22c3bc83c7b7d863bf138a7ca3418f1826b0b16d073d0aa87c16bc4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f74726565776172652d2546302539462538432542332d6c69676874677265656e3f7374796c653d666c61742d737175617265)](https://plant.treeware.earth/code-distortion/array-object-extended)[![Contributor Covenant](https://camo.githubusercontent.com/902d296a65b2997bada7e7717fd929d9177f3bd95414cbb5ea2ed843c680f314/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f6e7472696275746f72253230636f76656e616e742d76322e3125323061646f707465642d6666363962342e7376673f7374796c653d666c61742d737175617265)](.github/CODE_OF_CONDUCT.md)

***code-distortion/array-object-extended*** provides a substitute ArrayObject class that includes the methods missing from PHP's ArrayObject.

Introduction
------------

[](#introduction)

PHP has many [array functions](https://www.php.net/manual/en/ref.array.php) to manipulate arrays. It also has an [ArrayObject](https://www.php.net/manual/en/class.arrayobject.php) which is a class that acts like an array.

However, most of the regular array functions aren't implemented by `ArrayObject`.

This package offers `ArrayObjectExtended` which extends from PHP's `ArrayObject`, and adds many of the missing methods in.

`ArrayObjectExtended` is ***not*** intended to:

- *improve* the methods or functionality,
- be complete (it adds methods where it makes sense),
- be a Collection class, or
- provide a fluent interface.

It ***is*** designed to be faithful to PHP's original method names, parameter usage and return types.

In almost all cases, the only difference between the new class methods and the original is that the `$array` or `$haystack` parameter is removed (because the object inherently contains the array, so it doesn't need to be passed).

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

[](#installation)

Install the package via composer:

```
composer require code-distortion/array-object-extended
```

Usage
-----

[](#usage)

`ArrayObjectExtended` acts like PHP's `ArrayObject`. Instantiate and start using it like normal. e.g.

```
use CodeDistortion\ArrayObject\ArrayObjectExtended

$myArrayObject = new ArrayObjectExtended(['a', 'b', 'c']);

$myArrayObject->rsort();

foreach ($myArrayObject as $value) {
    print "$value\n";
}
```

You can extend from `ArrayObjectExtended` to add in your own functionality.

```
use ArrayAccess;
use CodeDistortion\ArrayObject\ArrayObjectExtended;
use Countable;
use IteratorAggregate;
use Serializable;

/**
 * @template TKey of integer|string
 * @template TValue of string
 * @template-implements IteratorAggregate
 * @template-implements ArrayAccess
 */
class MyArrayObject extends ArrayObjectExtended implements IteratorAggregate, ArrayAccess, Serializable, Countable
{
    // …
}
```

Available Methods
-----------------

[](#available-methods)

```
append(mixed $value): void
aRSort(int $flags = SORT_REGULAR): bool
aSort(int $flags = SORT_REGULAR): bool
changeKeyCase(int $case = CASE_LOWER): bool
chunk(int $length, bool $preserveKeys = false): array
column(string|int|null $columnKey, string|int|null $indexKey = null): array
//    array_combine() - not planning to implement
//    compact() - not planning to implement
contains(mixed $needle, bool $strict = false): bool // alias for inArray()
count(): int
//    array_count_values() - not implemented
current(): mixed|false
//    array_diff() - not implemented
//    array_diff_assoc() - not implemented
//    array_diff_key() - not implemented
//    array_diff_uassoc() - not implemented
//    array_diff_ukey() - not implemented
//    each() - not planning to implement
end(): mixed|false
exchangeArray(object|array $array): array
//    extract() - not planning to implement
//    array_fill() - not planning to implement
//    array_fill_keys() - not planning to implement
filter(?callable $callback = null, int $mode = 0): array
flip(): array
getArrayCopy(): array
getFlags(): int
getIterator(): Iterator
getIteratorClass(): string
inArray(mixed $needle, bool $strict = false): bool
//    array_intersect() - not implemented
//    array_intersect_assoc() - not implemented
//    array_intersect_key() - not implemented
//    array_intersect_uassoc() - not implemented
//    array_intersect_ukey() - not implemented
isList(): bool
key(): int|string|null
keyExists(mixed $key): bool
keyFirst(): string|int|null
keyLast(): string|int|null
keys(mixed $filterValue = null, bool $strict = false): array
kRSort(int $flags = SORT_REGULAR): bool
kSort(int $flags = SORT_REGULAR): bool
//    list() - not planning to implement
map(?callable $callback): array
max(): mixed
//    array_merge() - not implemented
//    array_merge_recursive() - not implemented
min(): mixed
//    array_multisort() - not implemented
natCaseSort(): bool
natSort(): bool
next(): mixed|false
offsetExists(mixed $key): bool
offsetGet(mixed $key): mixed
offsetSet(mixed $key, mixed $value): void
offsetUnset(mixed $key): void
//    array_pad() - not implemented
pop(): mixed|null
//    pos() - not planning to implement
prev(): mixed|false
//    array_product() - not implemented
push(mixed ...$values): int
rand(int $num = 1): array|string|int
//    range() - not planning to implement
//    array_reduce() - not implemented
//    array_replace() - not implemented
//    array_replace_recursive() - not implemented
reset(): mixed|false
reverse(bool $preserveKeys = false): void
rNatCaseSort(): bool
rNatSort(): bool
rSort(int $flags = SORT_REGULAR): bool
search(mixed $needle, bool $strict = false): string|int|false
serialize(): string
setFlags(int $flags): void
setIteratorClass(string $iteratorClass): void
shift(): mixed
shuffle(): bool
//    sizeof() - not planning to implement
slice(int $offset, ?int $length = null, bool $preserveKeys = false): array
sort(int $flags = SORT_REGULAR): bool
//    array_splice() - not implemented
//    array_sum() - not implemented
uASort(callable $callback): bool
//    array_udiff() - not implemented
//    array_udiff_assoc() - not implemented
//    array_udiff_uassoc() - not implemented
//    array_uintersect() - not implemented
//    array_uintersect_assoc() - not implemented
//    array_uintersect_uassoc() - not implemented
uKSort(callable $callback): bool
unique(int $flags = SORT_STRING): array
unserialize(string $data): void
unshift(mixed ...$values): int
uSort(callable $callback): bool
values(): array
//    array_walk() - not implemented
//    array_walk_recursive() - not implemented
```

Notes
-----

[](#notes)

ArrayObjects have a key `TKey` and value `TValue` type. You can define them in your classes when you extend from `ArrayObjectExtendend`.

For methods like `values()` and `map(..)`, a key consideration in having them return plain arrays is those key and value type requirements. If they updated the object, or returned new instances of the class, we can't be sure their keys and values would be valid types.

On-Change Hook
--------------

[](#on-change-hook)

Whenever a change is made to the data in an `ArrayObjectExtendend` instance, it calls `onAfterUpdate()`. This gives you an opportunity to clear internal caches, etc.

```
use ArrayAccess;
use CodeDistortion\ArrayObject\ArrayObjectExtended;
use Countable;
use IteratorAggregate;
use Serializable;

/**
 * @template TKey of integer|string
 * @template TValue of string
 * @template-implements IteratorAggregate
 * @template-implements ArrayAccess
 */
class MyArrayObject extends ArrayObjectExtended implements IteratorAggregate, ArrayAccess, Serializable, Countable
{
    /**
     * A hook that's called when the contents of this object has changed.
     *
     * @return void
     */
    protected function onAfterUpdate(): void
    {
        // clear internal caches, etc.
    }
}

$myArrayObject = new MyArrayObject();
// examples of methods that trigger onAfterUpdate()
$myArrayObject->unshift('hi');
$myArrayObject->push('there');
$myArrayObject->rSort();
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

### SemVer

[](#semver)

This library uses [SemVer 2.0.0](https://semver.org/) versioning. This means that changes to `X` indicate a breaking change: `0.0.X`, `0.X.y`, `X.y.z`. When this library changes to version 1.0.0, 2.0.0 and so forth, it doesn't indicate that it's necessarily a notable release, it simply indicates that the changes were breaking.

Treeware
--------

[](#treeware)

This package is [Treeware](https://treeware.earth). If you use it in production, then we ask that you [**buy the world a tree**](https://plant.treeware.earth/code-distortion/array-object-extended) to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.

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

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

### Code of Conduct

[](#code-of-conduct)

Please see [CODE\_OF\_CONDUCT](.github/CODE_OF_CONDUCT.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Tim Chandler](https://github.com/code-distortion)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance70

Regular maintenance activity

Popularity14

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity52

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

Every ~347 days

Total

3

Last Release

176d ago

PHP version history (3 changes)0.1.0PHP 8.2.\* | 8.3.\*

0.1.1PHP 8.2.\* | 8.3.\* | 8.4.\*

0.1.2PHP 8.2.\* | 8.3.\* | 8.4.\* | 8.5.\*

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/56794290?v=4)[Tim](/maintainers/code-distortion)[@code-distortion](https://github.com/code-distortion)

---

Top Contributors

[![code-distortion](https://avatars.githubusercontent.com/u/56794290?v=4)](https://github.com/code-distortion "code-distortion (4 commits)")

---

Tags

arrayserializablearrayobjectArrayAccesscountableIteratorAggregateArrayObjectExtended

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/code-distortion-array-object-extended/health.svg)

```
[![Health](https://phpackages.com/badges/code-distortion-array-object-extended/health.svg)](https://phpackages.com/packages/code-distortion-array-object-extended)
```

###  Alternatives

[doctrine/collections

PHP Doctrine Collections library that adds additional functionality on top of PHP arrays.

6.0k411.1M1.2k](/packages/doctrine-collections)[symfony/property-access

Provides functions to read and write from/to an object or array using a simple string notation

2.8k295.3M2.5k](/packages/symfony-property-access)[nette/utils

🛠 Nette Utils: lightweight utilities for string &amp; array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.

2.1k394.3M1.5k](/packages/nette-utils)[league/config

Define configuration arrays with strict schemas and access values with dot notation

564302.2M24](/packages/league-config)[cuyz/valinor

Dependency free PHP library that helps to map any input into a strongly-typed structure.

1.5k9.2M108](/packages/cuyz-valinor)[openlss/lib-array2xml

Array2XML conversion library credit to lalit.org

31052.5M47](/packages/openlss-lib-array2xml)

PHPackages © 2026

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