PHPackages                             ivir3zam/object-array-tools - 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. ivir3zam/object-array-tools

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

ivir3zam/object-array-tools
===========================

A full featured array behavior Abstract class for using in php libraries

1.1.2(9y ago)1159MITPHPPHP &gt;=5.4

Since Dec 21Pushed 9y ago1 watchersCompare

[ Source](https://github.com/IVIR3zaM/ObjectArrayTools)[ Packagist](https://packagist.org/packages/ivir3zam/object-array-tools)[ Docs](https://ivir3zam.github.com/)[ RSS](/packages/ivir3zam-object-array-tools/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (6)DependenciesVersions (7)Used By (0)

ObjectArrayTools
================

[](#objectarraytools)

[![Build Status](https://camo.githubusercontent.com/c72ca5f03c5c71c74004c49a02c88496793a3ad224d9d28c7847c77be6123b81/68747470733a2f2f7472617669732d63692e6f72672f49564952337a614d2f4f626a6563744172726179546f6f6c732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/IVIR3zaM/ObjectArrayTools) [![Code Climate](https://camo.githubusercontent.com/8dc8855d21b1656866b8a595f2a5d2d0577cca46e9f06b3098f91d13d191364f/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f49564952337a614d2f4f626a6563744172726179546f6f6c732f6261646765732f6770612e737667)](https://codeclimate.com/github/IVIR3zaM/ObjectArrayTools) [![Issue Count](https://camo.githubusercontent.com/9c203f893c638fe7df01a28d7a2e7f1b350825cd54f208b9abe68e3f959f69dc/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f49564952337a614d2f4f626a6563744172726179546f6f6c732f6261646765732f69737375655f636f756e742e737667)](https://codeclimate.com/github/IVIR3zaM/ObjectArrayTools) [![Test Coverage](https://camo.githubusercontent.com/d70500a6de62dc1387ae3ede1d635b6745aa5f0534957a5a08145c895f80fb32/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f49564952337a614d2f4f626a6563744172726179546f6f6c732f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/IVIR3zaM/ObjectArrayTools/coverage)

this library helps you to have an object as an active array with hooks for updating, inserting, deleting, sanitizing and filtering elements.

Technical Details
-----------------

[](#technical-details)

this library is different from builtin [ArrayObject](http://php.net/manual/en/class.arrayobject.php) class in PHP, and this deference is that this library is based on traits so you can use it in your classes that already extending some other classes and other differences is about hooks that help you to implement Observer Pattern for your ObjectArray, and also you have many methods equivalents to php native [Array Functions](http://php.net/manual/en/ref.array.php)

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

[](#installation)

The recommended way to install ObjectArrayTools is through [Composer](http://getcomposer.org).

```
# Install Composer
curl -sS https://getcomposer.org/installer | php
```

Next, run the Composer command to install the latest stable version of Guzzle:

```
php composer.phar require ivir3zam/object-array-tools
```

After installing, you need to require Composer's autoloader:

```
require 'vendor/autoload.php';
```

You can then later update ObjectArrayTools using composer:

```
composer.phar update
```

Examples
--------

[](#examples)

this library helps you to use your objects as an storage and it don't affect your current object functionality

### Basic Array Usage

[](#basic-array-usage)

this example only show you the basic usage of this library

```
use IVIR3aM\ObjectArrayTools\AbstractActiveArray;

class ActiveArray extends AbstractActiveArray {}

$object = new ActiveArray(['Hello', 'World']);

echo 'Number of elements: ' . count($object) . "\n";

foreach ($object as $string) {
    echo $string  . ' ';
}

echo "\n";

$object[1] = 'Visitor';

foreach ($object as $string) {
    echo $string  . ' ';
}

echo "\n";

/*
OUTPUT:

Number of elements: 2
Hello World
Hello Visitor

/*
```

### Save input in database and show output in browser

[](#save-input-in-database-and-show-output-in-browser)

in this example we try to have an array that when you write data in it, filter input for database and when you read from it, sanitize for html output

```
use IVIR3aM\ObjectArrayTools\AbstractActiveArray;

class DatabaseRecord extends AbstractActiveArray
{
    protected function sanitizeInputHook($offset, $data)
    {
        // some strong operation of sanitizing $data needed, this is only a sample
        return mysqli_real_escape_string($link, $data);
    }

    protected function sanitizeOutputHook($offset, $data)
    {
        return htmlspecialchars($data);
    }

    protected function updateHook($offset, $data, $oldData)
    {
        // some strong operation of updating database process needed, this is only a sample
        mysqli_query($link, "UPDATE SomeTable SET `Data` = '{$data}' WHERE `ID` = " . intval($offset));
    }

    protected function removeHook($offset, $oldData)
    {
        // some strong operation of updating database process needed, this is only a sample
        mysqli_query($link, "DELETE FROM SomeTable WHERE `ID` = " . intval($offset));
    }

    protected function insertHook($offset, $data)
    {
        mysqli_query($link, "INSERT INTO SomeTable SET `ID` = " . intval($offset) . ", `Data` = '{$data}'");
    }
}

$db = new DatabaseRecord();
$db[1] = "Lorem Ipsum script'; DELETE FROM SomeTable";
// mysqli_query($link, "INSERT INTO SomeTable SET `ID` = 1, `Data` = 'Lorem Ipsum script\'; DELETE FROM SomeTable'");

echo $db[1];
// Lorem Ipsum &lt;some&gt;script&lt;/some&gt;'; DELETE FROM SomeTable
```

### Sorting an array

[](#sorting-an-array)

you can see sorting functionality of this library here. there is a complete list of supported functions in [AbstractActiveArray](https://github.com/IVIR3zaM/ObjectArrayTools/blob/master/src/AbstractActiveArray.php) class documentation

```
use IVIR3aM\ObjectArrayTools\AbstractActiveArray;

class ActiveArray extends AbstractActiveArray {}

$object = new ActiveArray(['How', 'Are', 'You']);

print_r($object->getData());
/*
Array
(
    [0] => How
    [1] => Are
    [2] => You
)
*/

$object->sort();

print_r($object->getData());
/*
Array
(
    [0] => Are
    [1] => How
    [2] => You
)
*/
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

Established project with proven stability

 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 ~2 days

Total

6

Last Release

3422d ago

Major Versions

0.9.1 → 1.02016-12-23

### Community

Maintainers

![](https://www.gravatar.com/avatar/5f9922eaf03048c0fd429f6c01cc0d5168489a63cf1f60c6735caf5f4678ab7c?d=identicon)[IVIR3zaM](/maintainers/IVIR3zaM)

---

Top Contributors

[![IVIR3zaM](https://avatars.githubusercontent.com/u/4234196?v=4)](https://github.com/IVIR3zaM "IVIR3zaM (13 commits)")

---

Tags

array-accessiterator-objectobserver-arrayactive-array

### Embed Badge

![Health badge](/badges/ivir3zam-object-array-tools/health.svg)

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

###  Alternatives

[veewee/reflecta

Unleash the Power of Optics in your code!

12261.1k3](/packages/veewee-reflecta)[ayesh/case-insensitive-array

Class to store and access data in a case-insensitive fashion, while maintaining the integrity and functionality of a regular array.

1020.7k3](/packages/ayesh-case-insensitive-array)

PHPackages © 2026

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