codeinc/array-access

This package is abandoned and no longer maintained. No replacement package was suggested.

ArrayAccess library

1.2.0 2018-03-13 19:33 UTC

This package is auto-updated.

Last update: 2020-01-24 20:35:43 UTC


README

Usage

<?php
use CodeInc\ArrayAccess\ArrayAccessTrait;
use CodeInc\ArrayAccess\AbstractArrayAccess;
use CodeInc\ArrayAccess\ArrayAccess;

/*
 * As a trait
 */
class MyArrayAccesssibleClass1 implements \ArrayAccess {
	use ArrayAccessTrait;
	
	protected function getAccessibleArray():array {
        // returns the accessible array
    }
}

/*
 * As a parent class
 */
class MyArrayAccesssibleClass2 extends AbstractArrayAccess {
	protected function getAccessibleArray():array {
        // returns the accessible array
    }
}

/*
 * As a autonomous object
 */
$arrayAccessible = new ArrayAccess([1 =>  "One", 2 => "Two", 3 => "Three"]);
echo $arrayAccessible[2]; // echoes "Two"

Installation

This library is available through Packagist and can be installed using Composer:

composer require codeinc/array-access

License

The library is published under the MIT license (see LICENSE file).