Так можно, но без __get
<?php
class foo{
private $arr;
public function __construct()
{
$this->arr = new MyArray();
}
public function __get($property){
if(empty($this->$property)){
return -1;
} else {
return $this->$property;
}
}
}
class MyArray implements ArrayAccess {
private $container = array();
public function __construct() {
$this->container = array(
1 => "one" ,
2 => "two",
);
}
public function offsetSet($offset, $value) {
if (is_null($offset)) {
$this->container[] = $value;
} else {
$this->container[$offset] = $value;
}
}
public function offsetExists($offset) {
return isset($this->container[$offset]);
}
public function offsetUnset($offset) {
unset($this->container[$offset]);
}
public function offsetGet($offset) {
return isset($this->container[$offset]) ? $this->container[$offset] : -666;
}
}
$a = new foo();
var_dump($a->arrzzzz);
var_dump($a->arr[2]);
var_dump($a->arr[3]);