for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Trait ArrayAccessTrait
*
* @filesource ArrayAccessTrait.php
* @created 03.12.2017
* @package chillerlan\Traits\Interfaces
* @author Smiley <[email protected]>
* @copyright 2017 Smiley
* @license MIT
*/
namespace chillerlan\Traits\Interfaces;
* @implements ArrayAccess
* @link http://php.net/manual/class.arrayaccess.php
trait ArrayAccessTrait{
* @var array
protected $array = [];
* @var int
protected $offset = 0;
* @link http://php.net/manual/arrayaccess.offsetexists.php
* @inheritdoc
public function offsetExists($offset):bool{
return \array_key_exists($offset, $this->array);
}
* @link http://php.net/manual/arrayaccess.offsetget.php
public function offsetGet($offset){
return $this->array[$offset] ?? null;
* @link http://php.net/manual/arrayaccess.offsetset.php
public function offsetSet($offset, $value):void{
$offset !== null
? $this->array[$offset] = $value
: $this->array[] = $value;
* @link http://php.net/manual/arrayaccess.offsetunset.php
public function offsetUnset($offset):void{
unset($this->array[$offset]);