我有来自php文档的这个obj
类:
class obj implements ArrayAccess {
private $container = array();
public function __construct() {
$this->container = array(
"one" => 1,
"two" => 2,
"three" => 3,
);
}
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] : null;
}
}
现在,当我尝试使用像
这样的in_array函数时$obj = new obj;
echo in_array('1', $obj);
我得到了
Warning: in_array() expects parameter 2 to be array, object given
实现ArrayAccess的对象不应该像实际的数组一样吗?