<?php

class MyArray implements ArrayAccess  {
  private $data = array ();
  private function realOffset($offset) {
    return $offset + count($this->data) * intval($offset < 0);
  }
  public function offsetGet ($offset) {
    return $this->data[$this->realOffset($offset)];
  }
  public function offsetExists ($offset) {
    return array_key_exists( $offset, $this->data) 
        || array_key_exists(~$offset, $this->data);
  }
  public function offsetSet ($offset, $value) {
    $this->data[$this->realOffset($offset)] = $value;
  }
  public function offsetUnset ($offset) {
    unset($this->data[$this->realOffset($offset)]);
  }
  public function __construct() {
    $this->data = func_get_args();
  }
 }

$m = new MyArray(4, 5, 6);
echo sprintf("m[0] =%d, m[1] =%d, m[2] =%d\n", $m[0],  $m[1],  $m[2]);
echo sprintf("m[~0]=%d, m[~1]=%d, m[~2]=%d\n", $m[~0], $m[~1], $m[~2]);
