for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* DataStructures for PHP
*
* @link https://github.com/SiroDiaz/DataStructures
* @copyright Copyright (c) 2017 Siro Díaz Palazón
* @license https://github.com/SiroDiaz/DataStructures/blob/master/README.md (MIT License)
*/
namespace DataStructures\Lists\Traits;
use OutOfBoundsException;
* ArrayAccessTrait
* ArrayAccessTrait is a trait that implements the ArrayAccess methods
* to avoid repeating code in the List hierarchy classes.
* @author Siro Diaz Palazon <[email protected]>
trait ArrayAccessTrait {
abstract public function get($index);
abstract public function delete($index);
public function offsetSet($offset, $value) {
if (is_null($offset)) {
$offset = $this->size;
if($this->size === 0) {
$offset = 0;
}
$this->insert($offset, $value);
} else {
public function offsetExists($offset) {
try {
return $this->get($offset);
} catch(OutOfBoundsException $e) {
return false;
public function offsetUnset($offset) {
$this->delete($offset);
public function offsetGet($offset) {